I am using Postgres 10 and have table like this
Table "musicbrainz.acoustid_meta"
Column | Type | Collation | Nullable | Default
--------------+-------------------+-----------+----------+---------
id | integer | | not null |
track | character varying | | |
artist | character varying | | |
album | character varying | | |
album_artist | character varying | | |
track_no | character varying | | |
disc_no | character varying | | |
year | character varying | | |
Indexes:
"acoustid_meta_index" btree (id)
and I used to have csv files such as
id,track,artist,album,album_artist,track_no,disc_no,year
23033007,Satellite,Dave Matthews Band,Under the Table & Dreaming,Dave Matthews Band,3,\N,1994
that I imported with
psql jthinksearch -c "copy musicbrainz.acoustid_meta from '/home/ubuntu/code/acoustid-server/meta.full.$LATEST.csv' DELIMITER ',' CSV HEADER";
p
But now the files are jsonl files, with each line this this
{"id":339058430,"track":"Track14","artist":"Unknown Artist","album":"Unknown Title","album_artist":"Unknown Artist","track_no":14,"disc_no":null,"year":null}
How do I import these files safetly, I have tried using sed as a workaround to convert the file to csv but not quite right
cat $LATEST-meta-update.jsonl|sed
-e 's/{"id"://'
-e 's/"track"://'
-e 's/"artist"://'
-e 's/"album"://'
-e 's/"album_artist"://'
-e 's/"track_no"://'
-e 's/"disc_no"://'
-e 's/"year"://'
-e 's/\\\\"//g' >meta.csv
Also I have 5 different tables to import, so will have to construct sed for each.
Update Just realized the purpose of the end column that I ignored for simplicity
If is a new record to be added to table will have
"created":"2020-02-01T00:00:13.225963+00:00"
but if the records needs to replace existing record will have
"updated":"2020-02-03T13:20:12.988533+00:00"
When in do the insert using cross join populate_from_json how do I use a where clause to restrict to only use the ones with the created field ?