Skip to content

Instantly share code, notes, and snippets.

@JeffCarpenter
Last active December 4, 2023 02:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JeffCarpenter/757be2645a8671a2ce92aadc7568e5d0 to your computer and use it in GitHub Desktop.
Save JeffCarpenter/757be2645a8671a2ce92aadc7568e5d0 to your computer and use it in GitHub Desktop.
A simple script to import JSONL into PostgreSQL
psql -d mydb -c "create table log ( id serial primary key, data jsonb not null);"
# escape the slashes and pipe it in (otherwise Postgres will drop drop slashes intended to escape quotation marks, etc)
sed 's/\\/\\\\/g' log.jsonl | psql -d mydb -c "copy log ( data ) FROM STDIN;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment