Idea about sql command create table like

From: David BOURIAUD <david(dot)bouriaud(at)ac-rouen(dot)fr>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Idea about sql command create table like
Date: 2008-03-11 12:31:42
Message-ID: 200803111331.45772.david.bouriaud@ac-rouen.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,
I've seen that postgreSQL tries to follow sql standards as far as possible,
and that sometimes (often) brings it's own extentions. I've thought of one
concerning the sql command create table like.
As far as I've understood the documentation, one can create a table using
another table as a template.
Could it be possible then to add the possibility just to rename columns using
this command.
Here is an example to make my words a better meaning :

create table some_lib
(
some_code serial primary key,
some_text text
);

Now, I want a second table that has the same structure, I can do it two ways :

create table any_lib
(
any_code serial primary key,
any_text text
);

or

create table any_lib like (some_lib including constraints);

If I use the second option, the fields of any_lib will be named some_code and
some_text, which is not what I want, so I will have to use
alter table any_lib rename column some_code to any_code;
alter table any_lib rename column some_text to any_text;

Could it be possible to have a syntax that would allow to use "create table
like" to rename fields as well, for example :

create table any_lib like (some_lib including constraints) with names
(any_code, any_text);

Of course, this is just an example, and the tables schemas used are not big
enough to make it needed in this case, it is just here to illustrate my
meaning.
If one or more fields have to keep the name of the original table, then one
could use one keyword (maybe "default") like this :
create table any_lib like (some_lib including constraints) with names
(default, any_text);
This way, the first field would be named some_code...
What do you think of this ?

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message KaiGai Kohei 2008-03-11 12:56:09 [ANN] Now v8.3 based SE-PostgreSQL is available
Previous Message Karsten Hilbert 2008-03-11 12:15:56 Re: [ANNOUNCE] == Postgres Weekly News - March 09 2008 ==