0

DB2 command to Postgres command.

 db2 IMPORT FROM test.csv OF DEL MODIFIED BY USEDEFAULTS COMMITCOUNT 100000 "INSERT_UPDATE INTO TEST.person (name,old,sex)" > ${TEMPTXT}

How can i use postgres command to do the same thing like this db2 command to import from file to insert and update the table ?

guo lei li
  • 15
  • 7

1 Answers1

0

Postgres has COPY, but it doesn't perform update.So, first run COPY into a TEMP table and then merge into main table.

For a comma delimiter,

CREATE TEMP TABLE TEST.tmp_person (name text,old text,sex text)
COPY  TEST.tmp_person FROM test.csv WITH DELIMITER ',' CSV
--         ^temp table

There are various techniques in Postgres to do INSERT_UPDATE or merge. Refer this post. Use proper casting to appropriate target data types while inserting/updating.

Kaushik Nayak
  • 30,772
  • 5
  • 32
  • 45