Skip site navigation (1) Skip section navigation (2)

Re: [despammed] copy from file and overwrite existing

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Mattes Sarcander <mtsrc(at)systemausfall(dot)org>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [despammed] copy from file and overwrite existing
Date: 2005-06-27 16:03:55
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Mon, Jun 27, 2005 at 17:45:19 +0200,
  Mattes Sarcander <mtsrc(at)systemausfall(dot)org> wrote:
> Andreas Kretschmer <akretschmer(at)despammed(dot)com> wrote:
> > > I want to import data from a csv file into an existing, non-empty
> > > table. My problem is the fact that I get an "ERROR:  duplicate key
> > > violates unique constraint", because, as psql correctly grumbles,
> > > some entries are already inside the tables. I would like to
> > > overwrite these existing entries, as the data from the csv files is
> > > newer.
> > 
> > I suggest, use a separate import-table to copy the file in this table.
> > After you can work with usual SQL to delete old Records in the
> > destination table and insert the new records.
> Is there a way to automate this? The table is quite big, I expect some
> few hundred duplicate entries.

It should be hard to write SQL to delete the duplicates from the original
table and then insert all of the records from the import table. If you
don't need to look at the duplicates by hand to decide which version to
keep, then there shouldn't be a problem with developing a script to
do the load.

In response to

pgsql-novice by date

Next:From: AndreasDate: 2005-06-27 16:36:28
Subject: DANGER Windows version might hurt you
Previous:From: Mattes SarcanderDate: 2005-06-27 15:45:19
Subject: Re: [despammed] copy from file and overwrite existing

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group