Skip to content

Instantly share code, notes, and snippets.

@guyromm
Created April 4, 2023 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guyromm/a99b4f3f63ca2f340a46200e5216e9c5 to your computer and use it in GitHub Desktop.
Save guyromm/a99b4f3f63ca2f340a46200e5216e9c5 to your computer and use it in GitHub Desktop.
how to import a bunch of JSONL into your all time favorite database (postgresql, duh)
#!/bin/bash
F="$1"
T="$2"
for ((I=0;I<"$(cat "$F" |wc -l)";I=$I+1)) ; do
tail -n+$I $F | head -1 > /tmp/1.json
(echo '\set l1 `cat /tmp/1.json`' ; echo "insert into "$T" (v) values (:'l1')" ) | ./psql.sh -t -v ON_ERROR_STOP=1;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment