@@ -55,6 +55,9 @@ typedef struct
5555 BulkInsertState bistate ; /* bulk insert state */
5656} DR_intorel ;
5757
58+ /* the OID of the created table, for ExecCreateTableAs consumption */
59+ static Oid CreateAsRelid = InvalidOid ;
60+
5861static void intorel_startup (DestReceiver * self , int operation , TupleDesc typeinfo );
5962static void intorel_receive (TupleTableSlot * slot , DestReceiver * self );
6063static void intorel_shutdown (DestReceiver * self );
@@ -64,7 +67,7 @@ static void intorel_destroy(DestReceiver *self);
6467/*
6568 * ExecCreateTableAs -- execute a CREATE TABLE AS command
6669 */
67- void
70+ Oid
6871ExecCreateTableAs (CreateTableAsStmt * stmt , const char * queryString ,
6972 ParamListInfo params , char * completionTag )
7073{
@@ -75,6 +78,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
7578 Oid save_userid = InvalidOid ;
7679 int save_sec_context = 0 ;
7780 int save_nestlevel = 0 ;
81+ Oid relOid ;
7882 List * rewritten ;
7983 PlannedStmt * plan ;
8084 QueryDesc * queryDesc ;
@@ -98,7 +102,9 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
98102 Assert (!is_matview ); /* excluded by syntax */
99103 ExecuteQuery (estmt , into , queryString , params , dest , completionTag );
100104
101- return ;
105+ relOid = CreateAsRelid ;
106+ CreateAsRelid = InvalidOid ;
107+ return relOid ;
102108 }
103109 Assert (query -> commandType == CMD_SELECT );
104110
@@ -190,6 +196,11 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
190196 /* Restore userid and security context */
191197 SetUserIdAndSecContext (save_userid , save_sec_context );
192198 }
199+
200+ relOid = CreateAsRelid ;
201+ CreateAsRelid = InvalidOid ;
202+
203+ return relOid ;
193204}
194205
195206/*
@@ -421,6 +432,9 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
421432 myState -> rel = intoRelationDesc ;
422433 myState -> output_cid = GetCurrentCommandId (true);
423434
435+ /* and remember the new relation's OID for ExecCreateTableAs */
436+ CreateAsRelid = RelationGetRelid (myState -> rel );
437+
424438 /*
425439 * We can skip WAL-logging the insertions, unless PITR or streaming
426440 * replication is in use. We can skip the FSM in any case.
0 commit comments