aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/createas.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2014-08-25 15:32:18 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2014-08-25 15:32:18 -0400
commit301fcf33eb7fcbcf1da113dabeed90b8eaf656eb (patch)
tree4f8053b67cc03bb68aa920d1268ece2e2e1ceadd /src/backend/commands/createas.c
parentd6d6020f1cf33a63bbae59d370b75fa5e98017f0 (diff)
downloadpostgresql-301fcf33eb7fcbcf1da113dabeed90b8eaf656eb.tar.gz
postgresql-301fcf33eb7fcbcf1da113dabeed90b8eaf656eb.zip
Have CREATE TABLE AS and REFRESH return an OID
Other DDL commands are already returning the OID, which is required for future additional event trigger work. This is merely making these commands in line with the rest of utility command support.
Diffstat (limited to 'src/backend/commands/createas.c')
-rw-r--r--src/backend/commands/createas.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 96806eed98b..52451716f46 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -55,6 +55,9 @@ typedef struct
BulkInsertState bistate; /* bulk insert state */
} DR_intorel;
+/* the OID of the created table, for ExecCreateTableAs consumption */
+static Oid CreateAsRelid = InvalidOid;
+
static void intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo);
static void intorel_receive(TupleTableSlot *slot, DestReceiver *self);
static void intorel_shutdown(DestReceiver *self);
@@ -64,7 +67,7 @@ static void intorel_destroy(DestReceiver *self);
/*
* ExecCreateTableAs -- execute a CREATE TABLE AS command
*/
-void
+Oid
ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag)
{
@@ -75,6 +78,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
Oid save_userid = InvalidOid;
int save_sec_context = 0;
int save_nestlevel = 0;
+ Oid relOid;
List *rewritten;
PlannedStmt *plan;
QueryDesc *queryDesc;
@@ -98,7 +102,9 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
Assert(!is_matview); /* excluded by syntax */
ExecuteQuery(estmt, into, queryString, params, dest, completionTag);
- return;
+ relOid = CreateAsRelid;
+ CreateAsRelid = InvalidOid;
+ return relOid;
}
Assert(query->commandType == CMD_SELECT);
@@ -190,6 +196,11 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
/* Restore userid and security context */
SetUserIdAndSecContext(save_userid, save_sec_context);
}
+
+ relOid = CreateAsRelid;
+ CreateAsRelid = InvalidOid;
+
+ return relOid;
}
/*
@@ -421,6 +432,9 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
myState->rel = intoRelationDesc;
myState->output_cid = GetCurrentCommandId(true);
+ /* and remember the new relation's OID for ExecCreateTableAs */
+ CreateAsRelid = RelationGetRelid(myState->rel);
+
/*
* We can skip WAL-logging the insertions, unless PITR or streaming
* replication is in use. We can skip the FSM in any case.