foreign_table_like_03.diff
text/plain
Filename: foreign_table_like_03.diff
Type: text/plain
Part: 0
Message:
Re: CREATE FOREGIN TABLE LACUNA
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/create_foreign_table.sgml | 2 | 2 |
| src/backend/parser/gram.y | 1 | 0 |
| src/backend/parser/parse_utilcmd.c | 27 | 0 |
*** a/doc/src/sgml/ref/create_foreign_table.sgml
--- b/doc/src/sgml/ref/create_foreign_table.sgml
***************
*** 19,26 ****
<refsynopsisdiv>
<synopsis>
CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable> ( [
! { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ] [ NULL | NOT NULL ] }
! [, ... ]
] )
SERVER <replaceable class="parameter">server_name</replaceable>
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
--- 19,26 ----
<refsynopsisdiv>
<synopsis>
CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable> ( [
! { { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ NULL | NOT NULL ] | LIKE <replaceable>source_table</replaceable> } [, ... ]
! [ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ] }
] )
SERVER <replaceable class="parameter">server_name</replaceable>
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
*** 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 <srctable> portion of a CREATE TABLE statement into
* column definitions which recreate the user defined column portions of
* <srctable>.
*/
--- 630,636 ----
/*
* transformTableLikeClause
*
! * Change the LIKE <srctable> portion of a CREATE [FOREIGN] TABLE statement into
* column definitions which recreate the user defined column portions of
* <srctable>.
*/
***************
*** 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