Re: update from a csv file?

From: Christian Hammers <ch(at)lathspell(dot)de>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: update from a csv file?
Date: 2012-12-28 12:17:42
Message-ID: 20121228131742.35bbb279@notiac.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Am Fri, 28 Dec 2012 00:47:35 -0500
schrieb François Beausoleil <francois(at)teksol(dot)info>:

>
> Le 2012-12-27 à 09:54, Kirk Wythers a écrit :
>
> > 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 the database, but on rows that have
> > a primary key and have already been inserted (so I can't use COPY
> > FROM because it violates the primary key).
...

> You will want to COPY FROM on a new table that has the same structure:
>
> BEGIN;
> CREATE TEMPORARY TABLE original_table_name_temp( LIKE original_table_name INCLUDING ALL );
> COPY original_table_name_temp FROM stdin;

The "INCLUDING ALL" will also generate the same unique keys that let
the COPY fail in the original table so omit that.

bye,

-christian-

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ognjen Blagojevic 2012-12-28 14:34:50 Re: Tool to create database diagrams in postgreSQL
Previous Message Andreas Kretschmer 2012-12-28 12:04:31 Fwd: Re: [SQL] sql basic question