1

I know that by doing:

COPY test FROM '/path/to/csv/example.txt' DELIMITER ',' CSV;

I can import csv data to postgresql.

However, I do not have a static csv file. My csv file gets downloaded several times a day and it includes data which has previously been imported to the database. So, to get a consistent database I would have to leave out this old data.

My bestcase idea to realize this would be something like above. However, worstcase would be a java program manually checks each entry of the db with the csv file. Any recommendations for the implementation?

I really appreciate your answer!

user2051347
  • 1,609
  • 4
  • 23
  • 34
  • 3
    You can `COPY` full file to temp table and then `INSERT ... SELECT ...` only new record to the actual table. – Ihor Romanchenko Jan 17 '14 at 12:56
  • 1
    Sounds like you're looking for a bulk data merge, i.e. copy ignoring duplicates, or copy upsert. If so, see http://stackoverflow.com/q/13947327/398670, http://stackoverflow.com/q/17267417/398670 – Craig Ringer Jan 18 '14 at 02:02

1 Answers1

1

You can dump latest data to the temp table using COPY command and MERGE temp table with the live table.

If you are using JAVA program for execute COPY command, then try CopyManager API.

Parthi P
  • 65
  • 1
  • 8