Re: update table from a csv file - Mailing list pgsql-general

From Adrian Klaver
Subject Re: update table from a csv file
Date
Msg-id 50DC79A4.1090205@gmail.com
Whole thread Raw
In response to update table from a csv file  (Kirk Wythers <kirk.wythers@gmail.com>)
Responses Re: update table from a csv file  (Kirk Wythers <kirk.wythers@gmail.com>)
List pgsql-general
On 12/27/2012 08:27 AM, Kirk Wythers wrote:
> I have been using COPY FROM to do a mass import of records from CSV files into a new database. I have discover
however,a small number of records ( a few thousand) in one of the files that contain new data that needs to be added to
thedatabase, but on rows that have a primary key and have already been inserted (so I can't use COPY FROM because it
violatesthe primary key). 
>
> If the structure of the table is
>
> id    data1    data2    data3
>
> and the structure of the CSV file is
>
> id    data1    data2    data3
>
> and I need to update all the rows in data3 where the id = id.
>
> I have created a temporary table and used COPY FROM to load the update data into the temporary table. I seem to be
stuckhowever. I thought I should be able to use the UPDATE command to update all columns and all rows the table.id =
tmp_table.id
>
> Something like:
>
> UPDATE table FROM tmp_table WHERE table.id = tmp_table.id;
>
> Or am I completely off course?

No. Some questions though.

What version pf Postgres?
Is that the actual UPDATE statement, I see no SET?
Have you tried it?
If so and it failed what was the error?

>


--
Adrian Klaver
adrian.klaver@gmail.com


pgsql-general by date:

Previous
From: Kirk Wythers
Date:
Subject: update table from csv file
Next
From: Bexley Hall
Date:
Subject: Re: New Zealand Postgis DBA job vacancy