Thread: CREATE TABLE LIKE x INCLUDING CONSTRAINTS

CREATE TABLE LIKE x INCLUDING CONSTRAINTS

From
Greg Stark
Date:
Fixed previous patch by calling change_varattnos_of_a_node() to fix up
constraint expressions in case attribute positions don't line up.

change_varattnos_of_a_node is in tablecmds.c for inherited tables so this
means making it extern. I have a feeling it probably ought to move to some
file of functions for manipulating Nodes but I couldn't really find an
appropriate place. At first I was going to put it in ruleutils.c but then it
seems the other functions in that file go in builtins.h which would be a
strange place for this I think.

So in the end I left the functions in tablecmds.[ch] at least until someone
more familiar with the source tree suggests another pair of files for them to
be defined in.


--
greg

Attachment

Re: CREATE TABLE LIKE x INCLUDING CONSTRAINTS

From
Alvaro Herrera
Date:
Hum, how are you handling the case where I specify

CREATE TABLE LIKE x INCLUDING CONSTRAINTS EXCLUDING CONSTRAINTS ?

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: CREATE TABLE LIKE x INCLUDING CONSTRAINTS

From
Greg Stark
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:

> Hum, how are you handling the case where I specify
>
> CREATE TABLE LIKE x INCLUDING CONSTRAINTS EXCLUDING CONSTRAINTS ?

I have the last one taking priority. I could make it an error but don't see
much point in doing so. It seems to be making something an error for no
particular gain.

EXCLUDING CONSTRAINTS and EXCLUDING DEFAULTS are both kind of stupid since
they're the defaults. There's not much need for either except that EXCLUDING
DEFAULTS is in the standard and it would be weird not to follow the pattern.

And generally I feel like explaining corner cases like this -- when there's no
useful application of it -- to just clutter up documentation. The closest
analog is command-line options where often script writers want a way to
provide flags and then let a variable override those flags. But people rarely
do that kind of thing with SQL scripts. I suppose it does happen though. Maybe
it would be helpful to know how it will work.

--
greg

Re: CREATE TABLE LIKE x INCLUDING CONSTRAINTS

From
Bruce Momjian
Date:
Patch applied.  Thanks.

---------------------------------------------------------------------------


Greg Stark wrote:
>
> Fixed previous patch by calling change_varattnos_of_a_node() to fix up
> constraint expressions in case attribute positions don't line up.
>
> change_varattnos_of_a_node is in tablecmds.c for inherited tables so this
> means making it extern. I have a feeling it probably ought to move to some
> file of functions for manipulating Nodes but I couldn't really find an
> appropriate place. At first I was going to put it in ruleutils.c but then it
> seems the other functions in that file go in builtins.h which would be a
> strange place for this I think.
>
> So in the end I left the functions in tablecmds.[ch] at least until someone
> more familiar with the source tree suggests another pair of files for them to
> be defined in.
>

[ Attachment, skipping... ]

>
> --
> greg

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +