@@ -70,6 +70,7 @@ typedef struct
70
70
RangeVar * relation ; /* relation to create */
71
71
Relation rel ; /* opened/locked rel, if ALTER */
72
72
List * inhRelations ; /* relations to inherit from */
73
+ bool isforeign ; /* true if CREATE/ALTER FOREIGN TABLE */
73
74
bool isalter ; /* true if altering existing table */
74
75
bool hasoids ; /* does relation have an OID column? */
75
76
List * columns ; /* ColumnDef items */
@@ -195,9 +196,15 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
195
196
196
197
cxt .pstate = pstate ;
197
198
if (IsA (stmt , CreateForeignTableStmt ))
199
+ {
198
200
cxt .stmtType = "CREATE FOREIGN TABLE" ;
201
+ cxt .isforeign = true;
202
+ }
199
203
else
204
+ {
200
205
cxt .stmtType = "CREATE TABLE" ;
206
+ cxt .isforeign = false;
207
+ }
201
208
cxt .relation = stmt -> relation ;
202
209
cxt .rel = NULL ;
203
210
cxt .inhRelations = stmt -> inhRelations ;
@@ -515,11 +522,23 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
515
522
break ;
516
523
517
524
case CONSTR_CHECK :
525
+ if (cxt -> isforeign )
526
+ ereport (ERROR ,
527
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
528
+ errmsg ("constraints are not supported on foreign tables" ),
529
+ parser_errposition (cxt -> pstate ,
530
+ constraint -> location )));
518
531
cxt -> ckconstraints = lappend (cxt -> ckconstraints , constraint );
519
532
break ;
520
533
521
534
case CONSTR_PRIMARY :
522
535
case CONSTR_UNIQUE :
536
+ if (cxt -> isforeign )
537
+ ereport (ERROR ,
538
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
539
+ errmsg ("constraints are not supported on foreign tables" ),
540
+ parser_errposition (cxt -> pstate ,
541
+ constraint -> location )));
523
542
if (constraint -> keys == NIL )
524
543
constraint -> keys = list_make1 (makeString (column -> colname ));
525
544
cxt -> ixconstraints = lappend (cxt -> ixconstraints , constraint );
@@ -531,7 +550,12 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
531
550
break ;
532
551
533
552
case CONSTR_FOREIGN :
534
-
553
+ if (cxt -> isforeign )
554
+ ereport (ERROR ,
555
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
556
+ errmsg ("constraints are not supported on foreign tables" ),
557
+ parser_errposition (cxt -> pstate ,
558
+ constraint -> location )));
535
559
/*
536
560
* Fill in the current attribute's name and throw it into the
537
561
* list of FK constraints to be processed later.
@@ -555,8 +579,8 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
555
579
}
556
580
557
581
/*
558
- * Generate ALTER FOREIGN TABLE ALTER COLUMN statement which adds
559
- * per-column foreign data wrapper options for this column.
582
+ * If needed, generate ALTER FOREIGN TABLE ALTER COLUMN statement to add
583
+ * per-column foreign data wrapper options to this column after creation .
560
584
*/
561
585
if (column -> fdwoptions != NIL )
562
586
{
@@ -587,6 +611,13 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
587
611
static void
588
612
transformTableConstraint (CreateStmtContext * cxt , Constraint * constraint )
589
613
{
614
+ if (cxt -> isforeign )
615
+ ereport (ERROR ,
616
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
617
+ errmsg ("constraints are not supported on foreign tables" ),
618
+ parser_errposition (cxt -> pstate ,
619
+ constraint -> location )));
620
+
590
621
switch (constraint -> contype )
591
622
{
592
623
case CONSTR_PRIMARY :
@@ -640,7 +671,14 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
640
671
char * comment ;
641
672
ParseCallbackState pcbstate ;
642
673
643
- setup_parser_errposition_callback (& pcbstate , cxt -> pstate , table_like_clause -> relation -> location );
674
+ setup_parser_errposition_callback (& pcbstate , cxt -> pstate ,
675
+ table_like_clause -> relation -> location );
676
+
677
+ /* we could support LIKE in many cases, but worry about it another day */
678
+ if (cxt -> isforeign )
679
+ ereport (ERROR ,
680
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
681
+ errmsg ("LIKE is not supported for foreign tables" )));
644
682
645
683
relation = relation_openrv (table_like_clause -> relation , AccessShareLock );
646
684
@@ -2334,7 +2372,16 @@ transformAlterTableStmt(AlterTableStmt *stmt, const char *queryString)
2334
2372
pstate -> p_sourcetext = queryString ;
2335
2373
2336
2374
cxt .pstate = pstate ;
2337
- cxt .stmtType = "ALTER TABLE" ;
2375
+ if (stmt -> relkind == OBJECT_FOREIGN_TABLE )
2376
+ {
2377
+ cxt .stmtType = "ALTER FOREIGN TABLE" ;
2378
+ cxt .isforeign = true;
2379
+ }
2380
+ else
2381
+ {
2382
+ cxt .stmtType = "ALTER TABLE" ;
2383
+ cxt .isforeign = false;
2384
+ }
2338
2385
cxt .relation = stmt -> relation ;
2339
2386
cxt .rel = rel ;
2340
2387
cxt .inhRelations = NIL ;
0 commit comments