From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Aaron Held" <aaron(at)metrony(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: bulk imports with sequence |
Date: | 2002-08-20 14:53:45 |
Message-ID: | 5846.1029855225@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Aaron Held" <aaron(at)metrony(dot)com> writes:
> I am importing a large number of records monthly using the \copy (from text file)command.
> I would like to use a sequence as a unique row ID for display in my app.
> Is there any way to let postgresql generate the sequence itself. Currently the only way I
> can make it work is to grab the next seq value and insert my own numbers into the file
Right now the only reasonable way to do that is to do the \copy into a
temporary table (that's missing the sequence column) and then do
insert into realtable(column list) select * from temptable;
where the column list lists the columns you're pulling from the temp
table. The INSERT will substitute the default value (viz, nextval())
in the sequence column.
In 7.3 it'll be possible to do this in one step with no temp table:
COPY will accept a column list, so you can get the same effect just
with COPY.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Mathieu Arnold | 2002-08-20 15:34:10 | Re: sql subqueries problem |
Previous Message | Stephan Szabo | 2002-08-20 14:43:39 | Re: sql subqueries problem |