public inbox for [email protected]  
help / color / mirror / Atom feed
Create Table ... Like Including Default & Sequences
2+ messages / 2 participants
[nested] [flat]

* Create Table ... Like Including Default & Sequences
@ 2013-06-14 02:20  David Johnston <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: David Johnston @ 2013-06-14 02:20 UTC (permalink / raw)
  To: pgsql-docs

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.

David J.







--
View this message in context: http://postgresql.1045698.n5.nabble.com/Create-Table-Like-Including-Default-Sequences-tp5759108.html
Sent from the PostgreSQL - docs mailing list archive at Nabble.com.


-- 
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Create Table ... Like Including Default & Sequences
@ 2014-01-25 19:33  Bruce Momjian <[email protected]>
  parent: David Johnston <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruce Momjian @ 2014-01-25 19:33 UTC (permalink / raw)
  To: David Johnston <[email protected]>; +Cc: pgsql-docs

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  <[email protected]>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +


-- 
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs


Attachments:

  [text/x-diff] like.diff (1.1K, 2-like.diff)
  download | inline 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 ****
       </para>
       <para>
        Default expressions for the copied column definitions will only be
!       copied if <literal>INCLUDING DEFAULTS</literal> is specified.  The
        default behavior is to exclude default expressions, resulting in the
        copied columns in the new table having null defaults.
       </para>
--- 329,338 ----
       </para>
       <para>
        Default expressions for the copied column definitions will only be
!       copied if <literal>INCLUDING DEFAULTS</literal> is specified. 
!       Defaults that call database-modification functions, like
!       <function>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.
       </para>


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2014-01-25 19:33 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-06-14 02:20 Create Table ... Like Including Default & Sequences David Johnston <[email protected]>
2014-01-25 19:33 ` Bruce Momjian <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox