Skip to content

Instantly share code, notes, and snippets.

@bitner
Last active September 27, 2021 20:15
Show Gist options
  • Save bitner/cc33645b6eac4ceb85ac619d7a1befcc to your computer and use it in GitHub Desktop.
Save bitner/cc33645b6eac4ceb85ac619d7a1befcc to your computer and use it in GitHub Desktop.
pgstacdataload.sh
#!/bin/bash
TMP_TABLE_RANDOM=$(tr -dc a-z </dev/urandom | head -c 20)
TABLE="pgstac.tmp_items_$TMP_TABLE_RANDOM"
psql <<EOD
CREATE UNLOGGED TABLE $TABLE (
-- id text GENERATED ALWAYS AS (content->>'id') STORED,
-- partition text GENERATED ALWAYS AS (items_partition_name(stac_datetime(content))) STORED,
content jsonb
);
EOD
for i in $(ls *.gz | head -n20)
do
echo "Importing $i into tmp table"
gunzip -c $i | time psql -c "COPY $TABLE (content) FROM stdin"
done
psql <<EOD
DROP TABLE IF EXISTS $TABLE;
EOD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment