56
56
#include "rewrite/rewriteManip.h"
57
57
#include "utils/acl.h"
58
58
#include "utils/builtins.h"
59
+ #include "utils/guc.h"
59
60
#include "utils/lsyscache.h"
60
61
#include "utils/rel.h"
61
62
#include "utils/syscache.h"
@@ -150,6 +151,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
150
151
Oid namespaceid ;
151
152
Oid existing_relid ;
152
153
ParseCallbackState pcbstate ;
154
+ bool like_found = false;
153
155
154
156
/*
155
157
* We must not scribble on the passed-in CreateStmt, so copy it. (This is
@@ -242,7 +244,10 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
242
244
243
245
/*
244
246
* Run through each primary element in the table creation clause. Separate
245
- * column defs from constraints, and do preliminary analysis.
247
+ * column defs from constraints, and do preliminary analysis. We have to
248
+ * process column-defining clauses first because it can control the
249
+ * presence of columns which are referenced by columns referenced by
250
+ * constraints.
246
251
*/
247
252
foreach (elements , stmt -> tableElts )
248
253
{
@@ -254,21 +259,47 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
254
259
transformColumnDefinition (& cxt , (ColumnDef * ) element );
255
260
break ;
256
261
257
- case T_Constraint :
258
- transformTableConstraint (& cxt , (Constraint * ) element );
259
- break ;
260
-
261
262
case T_TableLikeClause :
263
+ if (!like_found )
264
+ {
265
+ cxt .hasoids = false;
266
+ like_found = true;
267
+ }
262
268
transformTableLikeClause (& cxt , (TableLikeClause * ) element );
263
269
break ;
264
270
271
+ case T_Constraint :
272
+ /* process later */
273
+ break ;
274
+
265
275
default :
266
276
elog (ERROR , "unrecognized node type: %d" ,
267
277
(int ) nodeTag (element ));
268
278
break ;
269
279
}
270
280
}
271
281
282
+ if (like_found )
283
+ {
284
+ /*
285
+ * To match INHERITS, the existance of any LIKE table with OIDs
286
+ * causes the new table to have oids. For the same reason,
287
+ * WITH/WITHOUT OIDs is also ignored with LIKE. We prepend
288
+ * because the first oid option list entry is honored. Our
289
+ * prepended WITHOUT OIDS clause will be overridden if an
290
+ * inherited table has oids.
291
+ */
292
+ stmt -> options = lcons (makeDefElem ("oids" ,
293
+ (Node * )makeInteger (cxt .hasoids )), stmt -> options );
294
+ }
295
+
296
+ foreach (elements , stmt -> tableElts )
297
+ {
298
+ Node * element = lfirst (elements );
299
+
300
+ if (nodeTag (element ) == T_Constraint )
301
+ transformTableConstraint (& cxt , (Constraint * ) element );
302
+ }
272
303
/*
273
304
* transformIndexConstraints wants cxt.alist to contain only index
274
305
* statements, so transfer anything we already have into save_alist.
@@ -860,6 +891,9 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
860
891
}
861
892
}
862
893
894
+ /* We use oids if at least one LIKE'ed table has oids. */
895
+ cxt -> hasoids = cxt -> hasoids || relation -> rd_rel -> relhasoids ;
896
+
863
897
/*
864
898
* Copy CHECK constraints if requested, being careful to adjust attribute
865
899
* numbers so they match the child.
0 commit comments