From: Craig Ringer <craig@postnewspapers.com.au>
To: Stewart Fritts <stewart.fritts@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6084: When Updating Tables with Select Into
Date: Thu, 30 Jun 2011 08:34:52 +0800
Message-ID: <4E0BC4AC.7040906@postnewspapers.com.au> (raw)
In-Reply-To: <201106291419.p5TEJbEZ034136@wwwmaster.postgresql.org>
References: <201106291419.p5TEJbEZ034136@wwwmaster.postgresql.org>
On 29/06/2011 10:19 PM, Stewart Fritts wrote:
> I recently migrated some data from one set of tables to another within a
> single schema. I did this by using a select...into query. Everything moved
> perfectly. However; I noticed that the sequence for the receiving table did
> not increment with the newly added data.
In general it's not expected to if the sequence wasn't used to generate
the IDs of the values inserted into the target table.
Can you show the SQL command you used? I'm guessing you used "SELECT *
...." rather than specifying a column-list that omits the generated
column, specifies it with value DEFAULT, or specifies it with
valuenextval('seq_name') . If you use 'SELECT *' then the target table's
sequence is never used because you specified that the primary key should
be copied from the old table along with all the rest of the data.
If you want to re-generate keys, instead of using:
SELECT * INTO ... FROM ....
use:
INSERT INTO ... (col1,col2,col3,col4)
SELECT col1, col2, col3, col4, ... FROM ...
and omit the PK column from the column-list so that the default value is
used during INSERT.
--
Craig Ringer
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-bugs@postgresql.org
Cc: craig@postnewspapers.com.au, stewart.fritts@gmail.com
Subject: Re: BUG #6084: When Updating Tables with Select Into
In-Reply-To: <4E0BC4AC.7040906@postnewspapers.com.au>
References: <201106291419.p5TEJbEZ034136@wwwmaster.postgresql.org> <4E0BC4AC.7040906@postnewspapers.com.au>
* 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