Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 86F761715C8 for ; Mon, 2 Jan 2012 10:33:23 -0400 (AST) Received: from mexforward.lss.emc.com ([128.222.32.20]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rhiwy-0007gV-D7 for pgsql-docs@postgresql.org; Mon, 02 Jan 2012 14:33:22 +0000 Received: from hop04-l1d11-si01.isus.emc.com (HOP04-L1D11-SI01.isus.emc.com [10.254.111.54]) by mexforward.lss.emc.com (Switch-3.4.3/Switch-3.4.3) with ESMTP id q02EX1DT002198 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 2 Jan 2012 09:33:03 -0500 Received: from mailhub.lss.emc.com (mailhub.lss.emc.com [10.254.222.129]) by hop04-l1d11-si01.isus.emc.com (RSA Interceptor); Mon, 2 Jan 2012 09:32:41 -0500 Received: from mxhub04.corp.emc.com (mxhub04.corp.emc.com [10.254.141.106]) by mailhub.lss.emc.com (Switch-3.4.3/Switch-3.4.3) with ESMTP id q02EWf01011350; Mon, 2 Jan 2012 09:32:41 -0500 Received: from mx22a.corp.emc.com ([169.254.1.77]) by mxhub04.corp.emc.com ([10.254.141.106]) with mapi; Mon, 2 Jan 2012 09:32:40 -0500 From: To: CC: Date: Mon, 2 Jan 2012 09:32:39 -0500 Subject: Re: CREATE TABLE LIKE, regarding constraints Thread-Topic: [DOCS] CREATE TABLE LIKE, regarding constraints Thread-Index: AczHudrN740kGUtpR9uTE7s7pbpWpABn261g Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-EMM-MHVC: 1 X-Pg-Spam-Score: -5.5 (-----) X-Archive-Number: 201201/1 X-Sequence-Number: 7152 -----Original Message----- From: Magnus Hagander [mailto:magnus@hagander.net]=20 Sent: Saturday, December 31, 2011 7:42 AM To: Sahagian, David Cc: pgsql-docs@postgresql.org Subject: Re: [DOCS] CREATE TABLE LIKE, regarding constraints On Fri, Dec 30, 2011 at 22:27, wrote: > www.postgresql.org/docs/9.0/static/sql-createtable.html > =3D=3D =3D=3D =3D=3D =3D=3D =3D=3D > 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 specifi= ed; other types of constraints will never be copied. > . . . > =3D=3D =3D=3D =3D=3D =3D=3D =3D=3D > > But I do see PK and UNIQUE constraints > =A0CONSTRAINT blah_pkey PRIMARY KEY (id), > =A0CONSTRAINT 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 res= ult in ? --=20 =A0Magnus Hagander =A0Me: http://www.hagander.net/ =A0Work: http://www.redpill-linpro.com/ Magnus,=20 I did some more "testing" of CREATE TABLE LIKE,=20 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=20 INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING = STORAGE=20 ); ++++++++++++++ no PRIMARY KEY no UNIQUE no indexes ++++++++++++++ CREATE TABLE noConstr_yesIndex_tbl ( like mytbl=20 INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING = STORAGE=20 ); ++++++++++++++ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "mytbl_pke= y" for table "mytbl" NOTICE: CREATE TABLE / UNIQUE will create implicit index "mytbl_hos= t_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,=20 but the doc probably deserves some clarification on the "relationship" betw= een=20 [INCLUDING CONSTRAINTS] and [INCLUDING INDEXES]. Thanks, -dvs-