I'd do it like this. Note I removed an if/else block in addition to
your changes.
I couldn't convince myself that this is worth pushing though; either we
push it to all branches (which seems unwarranted) or we create
back-patching hazards.
--
Álvaro Herrera 39°49'30"S 73°17'W
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 9dd30370da..2f20d81470 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -176,7 +176,6 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
Oid namespaceid;
Oid existing_relid;
ParseCallbackState pcbstate;
- bool is_foreign_table = IsA(stmt, CreateForeignTableStmt);
/*
* We must not scribble on the passed-in CreateStmt, so copy it. (This is
@@ -227,16 +226,8 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
/* Set up CreateStmtContext */
cxt.pstate = pstate;
- if (IsA(stmt, CreateForeignTableStmt))
- {
- cxt.stmtType = "CREATE FOREIGN TABLE";
- cxt.isforeign = true;
- }
- else
- {
- cxt.stmtType = "CREATE TABLE";
- cxt.isforeign = false;
- }
+ cxt.isforeign = IsA(stmt, CreateForeignTableStmt);
+ cxt.stmtType = cxt.isforeign ? "CREATE FOREIGN TABLE" : "CREATE TABLE";
cxt.relation = stmt->relation;
cxt.rel = NULL;
cxt.inhRelations = stmt->inhRelations;
@@ -333,8 +324,11 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
/*
* Postprocess check constraints.
+ *
+ * For regular tables all constraints can be marked valid immediately,
+ * because the table must be empty. Not so for foreign tables.
*/
- transformCheckConstraints(&cxt, !is_foreign_table ? true : false);
+ transformCheckConstraints(&cxt, !cxt.isforeign);
/*
* Postprocess extended statistics.