Index: src/backend/nodes/copyfuncs.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v retrieving revision 1.335 diff -c -p -c -r1.335 copyfuncs.c *** src/backend/nodes/copyfuncs.c 30 Apr 2006 18:30:38 -0000 1.335 --- src/backend/nodes/copyfuncs.c 16 Jun 2006 12:38:25 -0000 *************** _copyInhRelation(InhRelation *from) *** 1940,1946 **** InhRelation *newnode = makeNode(InhRelation); COPY_NODE_FIELD(relation); ! COPY_SCALAR_FIELD(including_defaults); return newnode; } --- 1940,1946 ---- InhRelation *newnode = makeNode(InhRelation); COPY_NODE_FIELD(relation); ! COPY_NODE_FIELD(options); return newnode; } Index: src/backend/nodes/equalfuncs.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v retrieving revision 1.271 diff -c -p -c -r1.271 equalfuncs.c *** src/backend/nodes/equalfuncs.c 30 Apr 2006 18:30:38 -0000 1.271 --- src/backend/nodes/equalfuncs.c 16 Jun 2006 12:38:25 -0000 *************** static bool *** 884,890 **** _equalInhRelation(InhRelation *a, InhRelation *b) { COMPARE_NODE_FIELD(relation); ! COMPARE_SCALAR_FIELD(including_defaults); return true; } --- 884,890 ---- _equalInhRelation(InhRelation *a, InhRelation *b) { COMPARE_NODE_FIELD(relation); ! COMPARE_NODE_FIELD(options); return true; } Index: src/backend/parser/analyze.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/parser/analyze.c,v retrieving revision 1.334 diff -c -p -c -r1.334 analyze.c *** src/backend/parser/analyze.c 30 Apr 2006 18:30:39 -0000 1.334 --- src/backend/parser/analyze.c 16 Jun 2006 12:38:25 -0000 *************** transformInhRelation(ParseState *pstate, *** 1075,1080 **** --- 1075,1085 ---- TupleConstr *constr; AclResult aclresult; + bool including_defaults = false; + bool including_constraints = false; + bool including_indexes = false; + ListCell *elem; + relation = heap_openrv(inhRelation->relation, AccessShareLock); if (relation->rd_rel->relkind != RELKIND_RELATION) *************** transformInhRelation(ParseState *pstate, *** 1095,1100 **** --- 1100,1136 ---- tupleDesc = RelationGetDescr(relation); constr = tupleDesc->constr; + foreach(elem, inhRelation->options) + { + int option = lfirst_int(elem); + switch (option) + { + case CREATE_TABLE_LIKE_INCLUDING_DEFAULTS: + including_defaults = true; + break; + case CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS: + including_defaults = false; + break; + case CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS: + including_constraints = true; + break; + case CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS: + including_constraints = false; + break; + case CREATE_TABLE_LIKE_INCLUDING_INDEXES: + including_indexes = true; + break; + case CREATE_TABLE_LIKE_EXCLUDING_INDEXES: + including_indexes = false; + break; + default: + elog(ERROR, "unrecognized CREATE TABLE LIKE option: %d", option); + } + } + + if (including_indexes) + elog(ERROR, "TODO"); + /* * Insert the inherited attributes into the cxt for the new table * definition. *************** transformInhRelation(ParseState *pstate, *** 1123,1129 **** def->typename = makeTypeNameFromOid(attribute->atttypid, attribute->atttypmod); def->inhcount = 0; ! def->is_local = false; def->is_not_null = attribute->attnotnull; def->raw_default = NULL; def->cooked_default = NULL; --- 1159,1165 ---- def->typename = makeTypeNameFromOid(attribute->atttypid, attribute->atttypmod); def->inhcount = 0; ! def->is_local = true; def->is_not_null = attribute->attnotnull; def->raw_default = NULL; def->cooked_default = NULL; *************** transformInhRelation(ParseState *pstate, *** 1138,1144 **** /* * Copy default if any, and the default has been requested */ ! if (attribute->atthasdef && inhRelation->including_defaults) { char *this_default = NULL; AttrDefault *attrdef; --- 1174,1180 ---- /* * Copy default if any, and the default has been requested */ ! if (attribute->atthasdef && including_defaults) { char *this_default = NULL; AttrDefault *attrdef; *************** transformInhRelation(ParseState *pstate, *** 1165,1170 **** --- 1201,1222 ---- def->cooked_default = pstrdup(this_default); } } + + if (including_constraints) { + int ccnum; + for(ccnum = 0; ccnum < tupleDesc->constr->num_check; ccnum++) { + char *ccname = tupleDesc->constr->check[ccnum].ccname; + char *ccbin = tupleDesc->constr->check[ccnum].ccbin; + Constraint *n = makeNode(Constraint); + n->contype = CONSTR_CHECK; + n->name = pstrdup(ccname); + n->raw_expr = stringToNode(ccbin); + /*DatumGetCString(DirectFunctionCall1(textout, DirectFunctionCall2(pg_get_expr, DirectFunctionCall1(textin, CStringGetDatum(ccbin)), ObjectIdGetDatum(RelationGetRelid(relation)))));*/ + n->cooked_expr = NULL; + n->indexspace = NULL; + cxt->ckconstraints = lappend(cxt->ckconstraints, (Node*)n); + } + } /* * Close the parent rel, but keep our AccessShareLock on it until xact Index: src/backend/parser/gram.y =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/parser/gram.y,v retrieving revision 2.545 diff -c -p -c -r2.545 gram.y *** src/backend/parser/gram.y 27 May 2006 17:38:45 -0000 2.545 --- src/backend/parser/gram.y 16 Jun 2006 12:38:27 -0000 *************** static void doNegateFloat(Value *v); *** 193,199 **** opt_grant_grant_option opt_grant_admin_option opt_nowait ! %type like_including_defaults %type OptRoleList %type OptRoleElem --- 193,199 ---- opt_grant_grant_option opt_grant_admin_option opt_nowait ! /*%type like_including_defaults*/ %type OptRoleList %type OptRoleElem *************** static void doNegateFloat(Value *v); *** 335,341 **** %type unreserved_keyword func_name_keyword %type col_name_keyword reserved_keyword ! %type TableConstraint TableLikeClause %type ColQualList %type ColConstraint ColConstraintElem ConstraintAttr %type key_actions key_delete key_match key_update key_action --- 335,343 ---- %type unreserved_keyword func_name_keyword %type col_name_keyword reserved_keyword ! %type TableConstraint TableLikeClause ! %type TableLikeOptionList ! %type TableLikeOption %type ColQualList %type ColConstraint ColConstraintElem ConstraintAttr %type key_actions key_delete key_match key_update key_action *************** static void doNegateFloat(Value *v); *** 385,391 **** HANDLER HAVING HEADER_P HOLD HOUR_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT ! INDEX INHERIT INHERITS INITIALLY INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION --- 387,393 ---- HANDLER HAVING HEADER_P HOLD HOUR_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT ! INDEX INDEXES INHERIT INHERITS INITIALLY INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION *************** ConstraintAttr: *** 1994,2013 **** * which is a part of SQL 200N */ TableLikeClause: ! LIKE qualified_name like_including_defaults { InhRelation *n = makeNode(InhRelation); n->relation = $2; ! n->including_defaults = $3; ! $$ = (Node *)n; } ; ! like_including_defaults: ! INCLUDING DEFAULTS { $$ = true; } ! | EXCLUDING DEFAULTS { $$ = false; } ! | /* EMPTY */ { $$ = false; } ; --- 1996,2022 ---- * which is a part of SQL 200N */ TableLikeClause: ! LIKE qualified_name TableLikeOptionList { InhRelation *n = makeNode(InhRelation); n->relation = $2; ! n->options = $3; $$ = (Node *)n; } ; ! TableLikeOptionList: ! TableLikeOptionList TableLikeOption { $$ = lappend_int($1, $2); } ! | /* EMPTY */ { $$ = NIL; } ! ; ! ! TableLikeOption: ! INCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_INCLUDING_DEFAULTS; } ! | EXCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS; } ! | INCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS; } ! | EXCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS; } ! | INCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_INCLUDING_INDEXES; } ! | EXCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_EXCLUDING_INDEXES; } ; *************** unreserved_keyword: *** 8421,8426 **** --- 8430,8436 ---- | INCLUDING | INCREMENT | INDEX + | INDEXES | INHERIT | INHERITS | INPUT_P Index: src/backend/parser/keywords.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/parser/keywords.c,v retrieving revision 1.171 diff -c -p -c -r1.171 keywords.c *** src/backend/parser/keywords.c 5 Mar 2006 15:58:32 -0000 1.171 --- src/backend/parser/keywords.c 16 Jun 2006 12:38:27 -0000 *************** static const ScanKeyword ScanKeywords[] *** 169,174 **** --- 169,175 ---- {"including", INCLUDING}, {"increment", INCREMENT}, {"index", INDEX}, + {"indexes", INDEXES}, {"inherit", INHERIT}, {"inherits", INHERITS}, {"initially", INITIALLY}, Index: src/include/nodes/parsenodes.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/nodes/parsenodes.h,v retrieving revision 1.310 diff -c -p -c -r1.310 parsenodes.h *** src/include/nodes/parsenodes.h 30 Apr 2006 18:30:40 -0000 1.310 --- src/include/nodes/parsenodes.h 16 Jun 2006 12:38:28 -0000 *************** typedef struct InhRelation *** 403,409 **** { NodeTag type; RangeVar *relation; ! bool including_defaults; } InhRelation; /* --- 403,409 ---- { NodeTag type; RangeVar *relation; ! List *options; } InhRelation; /* *************** typedef struct CreateStmt *** 1026,1031 **** --- 1026,1040 ---- char *tablespacename; /* table space to use, or NULL */ } CreateStmt; + typedef enum CreateStmtLikeOption { + CREATE_TABLE_LIKE_INCLUDING_DEFAULTS, + CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS, + CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS, + CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS, + CREATE_TABLE_LIKE_INCLUDING_INDEXES, + CREATE_TABLE_LIKE_EXCLUDING_INDEXES, + } CreateStmtLikeOption; + /* ---------- * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt *