Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W78yx-0001Rq-UD for pgsql-docs@arkaria.postgresql.org; Sat, 25 Jan 2014 19:33:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W78yx-00041u-3l for pgsql-docs@arkaria.postgresql.org; Sat, 25 Jan 2014 19:33:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W78yw-00041o-Ev for pgsql-docs@postgresql.org; Sat, 25 Jan 2014 19:33:30 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W78yp-0001pt-BQ for pgsql-docs@postgresql.org; Sat, 25 Jan 2014 19:33:29 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1W78yn-0000qS-Us; Sat, 25 Jan 2014 14:33:21 -0500 Date: Sat, 25 Jan 2014 14:33:21 -0500 From: Bruce Momjian To: David Johnston Cc: pgsql-docs@postgresql.org Subject: Re: Create Table ... Like Including Default & Sequences Message-ID: <20140125193321.GB9750@momjian.us> References: <1371176405220-5759108.post@n5.nabble.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mYCpIKhGyMATD0i+" Content-Disposition: inline In-Reply-To: <1371176405220-5759108.post@n5.nabble.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org --mYCpIKhGyMATD0i+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jun 13, 2013 at 07:20:05PM -0700, David Johnston wrote: > In the documentation for "Create Table" the following paragraph appears under > the definition for LIKE: > > "Default expressions for the copied column definitions will only be copied > if INCLUDING DEFAULTS is specified. The default behavior is to exclude > default expressions, resulting in the copied columns in the new table having > null defaults." > > I would like to suggest adding a sentence between the first and second: > > Defaults created via the "serial" and "bigserial" construct - or that use > "nextval(...)" generally - are copied as-is resulting in both tables sharing > the same underlying sequence. > > Note that this is technically contrary to the statement: > > Unlike INHERITS, the new table and original table are completely decoupled > after creation is complete. > > I'm working in 9.0 and noticed this incidentally when a FK constraint failed > but the expected ID was somewhere in the 10s while the actual was somewhere > upward of 80,000 which clued me into the fact that the original sequence was > being used. > > As an aside it may be worth noting (or linking to) a quick way to change the > default on the new table if this is done in error and a correction is > desired. For my purposes I'll likely just leave it alone. Oh, that is something I had not considered. I have applied the attached doc patch for 9.4. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --mYCpIKhGyMATD0i+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="like.diff" diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml new file mode 100644 index a422edd..e0b8a4e *** a/doc/src/sgml/ref/create_table.sgml --- b/doc/src/sgml/ref/create_table.sgml *************** CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY *** 329,335 **** Default expressions for the copied column definitions will only be ! copied if INCLUDING DEFAULTS is specified. The default behavior is to exclude default expressions, resulting in the copied columns in the new table having null defaults. --- 329,338 ---- Default expressions for the copied column definitions will only be ! copied if INCLUDING DEFAULTS is specified. ! Defaults that call database-modification functions, like ! nextval, create a linkage between the original and ! new tables. The default behavior is to exclude default expressions, resulting in the copied columns in the new table having null defaults. --mYCpIKhGyMATD0i+ Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs --mYCpIKhGyMATD0i+--