Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id BB501B5DBD0 for ; Wed, 29 Jun 2011 21:33:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 93735-02 for ; Thu, 30 Jun 2011 00:33:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id 8BBFBB5D803 for ; Wed, 29 Jun 2011 21:33:40 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id 94D6F4B9; Wed, 29 Jun 2011 20:33:39 -0400 (EDT) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id rbhkL9CB5LG8; Wed, 29 Jun 2011 20:33:38 -0400 (EDT) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id 8C4C927; Wed, 29 Jun 2011 20:33:38 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 7776BAECAA; Thu, 30 Jun 2011 08:33:37 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id HySlvAXdk2K9; Thu, 30 Jun 2011 08:33:31 +0800 (WST) Received: from [10.1.1.7] (124-169-57-156.dyn.iinet.net.au [124.169.57.156]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id DC7D2AECAB; Thu, 30 Jun 2011 08:33:30 +0800 (WST) Message-ID: <4E0BC4AC.7040906@postnewspapers.com.au> Date: Thu, 30 Jun 2011 08:34:52 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Stewart Fritts CC: pgsql-bugs@postgresql.org Subject: Re: BUG #6084: When Updating Tables with Select Into References: <201106291419.p5TEJbEZ034136@wwwmaster.postgresql.org> In-Reply-To: <201106291419.p5TEJbEZ034136@wwwmaster.postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/228 X-Sequence-Number: 30607 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