pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: amoeller@infosys.de
Cc: pgsql-sql@postgresql.org
Subject: Re: copy into serial field with auto_increment
Date: Thu, 19 Apr 2001 22:39:07 +0100
Message-ID: <200104192139.f3JLd7U23180@linda.lfix.co.uk> (raw)
In-Reply-To: <amoeller@infosys.de> <3ADD6996.B4D2CCEA@infosys.de>

Andy wrote:
  >i've got a textfile of data separated by '|'. One of the fields in my
  >table is a serial (auto_increment) field.
  >When i import the data with the copy command i get duplicate key error.
  >The key is the serial - field.
  >I recognized that the copy command doesn't auto_increment the serial
  >field. I come from mysql and pushed a 0 into the serial field. But it
  >doesn't work. I tested it with an empty field, but it failed to.
  >How could i make it work ??
 
It's not clear to me whether your error is during COPY or afterwards.

If it is during COPY, edit your textfile and assign unique values to
each row.


If it is afterwards, use 

  SELECT setval('sequence_name', SELECT max(serial_field) FROM table);

to set the sequence value.  (You probably have to be running 7.1 to use
a sub-select like that.)


-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "For I am persuaded, that neither death, nor life, nor 
      angels, nor principalities, nor powers, nor things 
      present, nor things to come, nor height, nor depth, 
      nor any other creature, shall be able to separate us 
      from the love of God, which is in Christ Jesus our 
      Lord."     Romans 8:38,39 





view thread (2+ messages)

Message-ID: <200104192139.f3JLd7U23180@linda.lfix.co.uk>
Permalink:  ../200104192139.f3JLd7U23180@linda.lfix.co.uk/
Also on:    postgresql.org/message-id/200104192139.f3JLd7U23180@linda.lfix.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: olly@lfix.co.uk, amoeller@infosys.de
  Subject: Re: copy into serial field with auto_increment
  In-Reply-To: <200104192139.f3JLd7U23180@linda.lfix.co.uk>
  References: <200104192139.f3JLd7U23180@linda.lfix.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox