Re: CREATE TABLE LIKE, regarding constraints

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: david(dot)sahagian(at)emc(dot)com, pgsql-docs(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE, regarding constraints
Date: 2012-08-26 20:35:19
Message-ID: 20120826203519.GN10814@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Mon, Jan 2, 2012 at 08:31:43PM +0100, Magnus Hagander wrote:
> On Mon, Jan 2, 2012 at 15:32, <david(dot)sahagian(at)emc(dot)com> wrote:
> > On Fri, Dec 30, 2011 at 22:27,  <david(dot)sahagian(at)emc(dot)com> 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,
> > 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.
>
> Ah, that explains why I couldn't reproduce it.
>
>
> > I have no problem with this behavior,
> > but the doc probably deserves some clarification on the "relationship" between
> > [INCLUDING CONSTRAINTS] and [INCLUDING INDEXES].
>
> That might be a good idea, yes. Feel like cooking up a patch?

I have applied the attached patch based on this report.

It is confusing that INCLUDING CONSTRAINTS only copies CHECK
constraints, and INCLUDING INDEXES is required for PRIMARY KEY and
UNIQUE constraints. Is there a reason our logic is so odd here? The
SQL standard?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
constraints.diff text/x-diff 1.8 KB

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Peter Eisentraut 2012-08-27 03:43:45 Re: somewhat wrong archive_command example
Previous Message Bruce Momjian 2012-08-25 23:40:26 Re: somewhat wrong archive_command example