public inbox for [email protected]  
help / color / mirror / Atom feed
From: [email protected]
To: [email protected]
Cc: [email protected]
Subject: Re: CREATE TABLE LIKE, regarding constraints
Date: Mon, 2 Jan 2012 09:32:39 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <CABUevExTjCDGhskyXid+6pHSoatUO2u0L7zJ-jAJf43WaLMmtg@mail.gmail.com>
References: <[email protected]>
	<CABUevExTjCDGhskyXid+6pHSoatUO2u0L7zJ-jAJf43WaLMmtg@mail.gmail.com>

-----Original Message-----
From: Magnus Hagander [mailto:[email protected]] 
Sent: Saturday, December 31, 2011 7:42 AM
To: Sahagian, David
Cc: [email protected]
Subject: Re: [DOCS] CREATE TABLE LIKE, regarding constraints

On Fri, Dec 30, 2011 at 22:27,  <[email protected]> wrote:
> www.postgresql.org/docs/9.0/static/sql-createtable.html
> == == == == ==
> LIKE parent_table [ like_option ... ]
> . . .
> Not-null constraints are always copied to the new table.
> CHECK constraints will only be copied if INCLUDING CONSTRAINTS is specified; other types of constraints will never be copied.
> . . .
> == == == == ==
>
> But I do see PK and UNIQUE constraints
>  CONSTRAINT blah_pkey PRIMARY KEY (id),
>  CONSTRAINT blah_host_id_key UNIQUE (host_id)
> in the def of the new table.

Can you provide the commands you ran to make that happen? It doesn't
happen for me in a trivial test.

> Also, why is there no discussion of what "EXCLUDING CONSTRAINTS" will result in ?

-- 
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/


Magnus, 
I did some more "testing" of CREATE TABLE LIKE, 
and now see that [INCLUDING INDEXES] also can cause PRIMARY KEY and UNIQUE constraints to become part of the new table.

++++++++++++++
 CREATE TABLE yesConstr_noIndex_tbl (
   like mytbl 
   INCLUDING DEFAULTS  INCLUDING CONSTRAINTS                     INCLUDING STORAGE 
 );
++++++++++++++
  no PRIMARY KEY
  no UNIQUE
  no indexes

++++++++++++++
 CREATE TABLE  noConstr_yesIndex_tbl (
   like mytbl 
   INCLUDING DEFAULTS                        INCLUDING INDEXES   INCLUDING STORAGE 
 );
++++++++++++++
  NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "mytbl_pkey"           for table "mytbl"
  NOTICE:  CREATE TABLE / UNIQUE      will create implicit index "mytbl_host_id_key"    for table "mytbl"

  CONSTRAINT mytbl_pkey PRIMARY KEY (id),
  CONSTRAINT mytbl_host_id_key UNIQUE (host_id)
  and 2 unrelated indexes: (a_diff_col) (yet_a_diff_col)


I have no problem with this behavior, 
but the doc probably deserves some clarification on the "relationship" between 
[INCLUDING CONSTRAINTS] and [INCLUDING INDEXES].

Thanks,
-dvs-






view thread (5+ messages)  latest in thread

reply

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: CREATE TABLE LIKE, regarding constraints
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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