*** a/doc/src/sgml/ref/create_foreign_table.sgml --- b/doc/src/sgml/ref/create_foreign_table.sgml *************** *** 19,26 **** CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name ( [ ! { column_name data_type [ OPTIONS ( option 'value' [, ... ] ) ] [ NULL | NOT NULL ] } ! [, ... ] ] ) SERVER server_name [ OPTIONS ( option 'value' [, ... ] ) ] --- 19,26 ---- CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name ( [ ! { { column_name data_type [ NULL | NOT NULL ] | LIKE source_table } [, ... ] ! [ OPTIONS ( option 'value' [, ... ] ) ] } ] ) SERVER server_name [ OPTIONS ( option 'value' [, ... ] ) ] *** a/src/backend/parser/gram.y --- b/src/backend/parser/gram.y *************** *** 3945,3950 **** ForeignTableElementList: --- 3945,3951 ---- ForeignTableElement: columnDef { $$ = $1; } + | TableLikeClause { $$ = $1; } ; /***************************************************************************** *** a/src/backend/parser/parse_utilcmd.c --- b/src/backend/parser/parse_utilcmd.c *************** *** 66,71 **** typedef struct --- 66,72 ---- { ParseState *pstate; /* overall parser state */ const char *stmtType; /* "CREATE [FOREIGN] TABLE" or "ALTER TABLE" */ + char relkind; /* r = ordinary table, f = foreign table, cf. pg_catalog.pg_class */ RangeVar *relation; /* relation to create */ Relation rel; /* opened/locked rel, if ALTER */ List *inhRelations; /* relations to inherit from */ *************** *** 194,202 **** transformCreateStmt(CreateStmt *stmt, const char *queryString) --- 195,209 ---- cxt.pstate = pstate; if (IsA(stmt, CreateForeignTableStmt)) + { cxt.stmtType = "CREATE FOREIGN TABLE"; + cxt.relkind = 'f'; + } else + { cxt.stmtType = "CREATE TABLE"; + cxt.relkind = 'r'; + } cxt.relation = stmt->relation; cxt.rel = NULL; cxt.inhRelations = stmt->inhRelations; *************** *** 623,629 **** transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint) /* * transformTableLikeClause * ! * Change the LIKE portion of a CREATE TABLE statement into * column definitions which recreate the user defined column portions of * . */ --- 630,636 ---- /* * transformTableLikeClause * ! * Change the LIKE portion of a CREATE [FOREIGN] TABLE statement into * column definitions which recreate the user defined column portions of * . */ *************** *** 652,657 **** transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla --- 659,683 ---- table_like_clause->relation->relname))); cancel_parser_errposition_callback(&pcbstate); + + /* + * For foreign tables, disallow some options. + */ + if (cxt->relkind == 'f') + { + if (table_like_clause->options & CREATE_TABLE_LIKE_CONSTRAINTS) + { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("ERROR: foreign tables do not support LIKE INCLUDING CONSTRAINTS"))); + } + else if (table_like_clause->options & CREATE_TABLE_LIKE_INDEXES) + { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("ERROR: foreign tables do not support LIKE INCLUDING INDEXES"))); + } + } /* * Check for privileges