Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E431B4759B0 for ; Tue, 20 Aug 2002 10:54:58 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 569964759A1 for ; Tue, 20 Aug 2002 10:54:58 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g7KErjZM005847; Tue, 20 Aug 2002 10:53:45 -0400 (EDT) To: "Aaron Held" Cc: pgsql-sql@postgresql.org Subject: Re: bulk imports with sequence In-reply-to: <000b01c24840$7b5a0880$4b00a8c0@metrony.com> References: <20020819094344.C31592-100000@megazone23.bigpanda.com> <761958859.1029831297@sauron> <000b01c24840$7b5a0880$4b00a8c0@metrony.com> Comments: In-reply-to "Aaron Held" message dated "Tue, 20 Aug 2002 07:55:24 -0400" Date: Tue, 20 Aug 2002 10:53:45 -0400 Message-ID: <5846.1029855225@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/293 X-Sequence-Number: 9139 "Aaron Held" 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