Re: About the CREATE TABLE LIKE indexes vs constraints issue

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Brendan Jurd <direvus(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: About the CREATE TABLE LIKE indexes vs constraints issue
Date: 2009-12-23 23:29:17
Message-ID: 16267.1261610957@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jeff Davis <pgsql(at)j-davis(dot)com> writes:
> Honestly, I've never used LIKE in a table definition aside from one-off
> design experiments. For that kind of thing, what I want is to just get
> everything (except perhaps FKs if the above situation applies), and I
> adjust it from there. Are there people out there who use LIKE in their
> production schema files?

The only concrete application I've heard of for LIKE is to create
something that is going to be part of a partitioned table later.
That is, instead of

create table partition23 () inherits (partition_parent);

you do

create table partition23 (like partition_parent);
...
alter table partition23 inherit partition_parent;

The advantage of the latter is you can tweak the new partition
(eg, load data into it) before you make it a live part of the
partition set.

So in this context it's entirely likely that people would be using
LIKE in scripted procedures. However, it's not immediately obvious
to me whether the current definitions of the LIKE options are well
suited to this application. The lack of any support for copying
foreign keys seems a bit questionable for instance. Now if you plan
a bulk load before taking the partition live, maybe you'd not want
to enable foreign key checks till after --- but the same would hold
for indexes, so why is there an option to copy one but not the other?

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Williamson 2009-12-23 23:59:07 Re: About the CREATE TABLE LIKE indexes vs constraints issue
Previous Message Bruce Momjian 2009-12-23 23:12:36 Re: Removing pg_migrator limitations