[PATCHES] CREATE TABLE LIKE INCLUDING CONSTRAINTS

2006-06-16 Thread Greg Stark


I just managed to crash the server so I guess this isn't finished, but I'm
posting it in the post early post often spirit. Aside from error checks it
also needs docs and tests of course.

This patch implements an option to copy check constraints when using LIKE.
Because the standard specifically excludes constraints (except NOT NULL) from
being copied it defaults to off and has to be explicitly requested by the user
using the nonstandard extension INCLUDING CONSTRAINTS.

This is especially useful in combination with ALTER TABLE INHERIT since
without it there's no convenient way to create eligible tables for adding to
the inheritance tree. The user would have to manually reenter every check
constraint.

Question:

. Is nodeToString() the right thing here? 
  
Currently only check constraints are added because only check constraints are
handled by inheritance. I intend to add foreign key constraints when I add
them to the rest of inheritance which will necessitate a scan of pg_constraint
instead of using the relcache :(



postgres=# create table z (i integer check (i=0));
CREATE TABLE
postgres=# create table zz (like z including constraints);
CREATE TABLE
postgres=# \d zz
  Table public.zz
 Column |  Type   | Modifiers 
+-+---
 i  | integer | 
Check constraints:
z_i_check CHECK (i = 0)




like.patch2
Description: Binary data





-- 
greg

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [PATCHES] CREATE TABLE LIKE INCLUDING CONSTRAINTS

2006-06-16 Thread Greg Stark

Fixed the bug, added docs and tests.




like.patch3
Description: Binary data


The previous message explaining the patch:


Greg Stark [EMAIL PROTECTED] writes:

 This patch implements an option to copy check constraints when using LIKE.
 Because the standard specifically excludes constraints (except NOT NULL) from
 being copied it defaults to off and has to be explicitly requested by the user
 using the nonstandard extension INCLUDING CONSTRAINTS.
 
 This is especially useful in combination with ALTER TABLE INHERIT since
 without it there's no convenient way to create eligible tables for adding to
 the inheritance tree. The user would have to manually reenter every check
 constraint.
 
 Question:
 
 . Is nodeToString() the right thing here? 
   
 Currently only check constraints are added because only check constraints are
 handled by inheritance. I intend to add foreign key constraints when I add
 them to the rest of inheritance which will necessitate a scan of pg_constraint
 instead of using the relcache :(
 
 
 postgres=# create table z (i integer check (i=0));
 CREATE TABLE
 postgres=# create table zz (like z including constraints);
 CREATE TABLE
 postgres=# \d zz
   Table public.zz
  Column |  Type   | Modifiers 
 +-+---
  i  | integer | 
 Check constraints:
 z_i_check CHECK (i = 0)
-- 
greg

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [PATCHES] CREATE TABLE LIKE INCLUDING CONSTRAINTS

2006-06-16 Thread Greg Stark

Greg Stark [EMAIL PROTECTED] writes:

  This patch implements an option to copy check constraints when using LIKE.

Ah, found a problem. I need to do a change_varattnos_of_a_node() call here.
Should this function maybe be promoted to some other file like ruleutils.c?

-- 
greg


---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings