Last active
September 27, 2021 20:15
-
-
Save bitner/cc33645b6eac4ceb85ac619d7a1befcc to your computer and use it in GitHub Desktop.
pgstacdataload.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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