#!/usr/bin/env bash set -euo pipefail # Usage: # ./import_jsonl.sh "postgresql://user:pass@host:5432/dbname" gloss doc /path/to/file.jsonl # # Notes: # - Creates table if it doesn't exist. # - Inserts each JSON line into a jsonb column. # - Skips blank lines. DB_URL="${1:?db url}" TABLE="${2:?table name}" COL="${3:?json column name}" FILE="${4:?jsonl file path}" psql "$DB_URL" -v ON_ERROR_STOP=1 < ''; -- optional: show count inserted this run SELECT count(*) AS inserted_now FROM _jsonl_stage WHERE btrim(line) <> ''; SQL