PostgreSQL Source Code  git master
view.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * view.c
4  * use rewrite rules to construct views
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/commands/view.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/relation.h"
18 #include "access/xact.h"
19 #include "catalog/namespace.h"
20 #include "commands/defrem.h"
21 #include "commands/tablecmds.h"
22 #include "commands/view.h"
23 #include "miscadmin.h"
24 #include "nodes/makefuncs.h"
25 #include "nodes/nodeFuncs.h"
26 #include "parser/analyze.h"
27 #include "parser/parse_relation.h"
28 #include "rewrite/rewriteDefine.h"
29 #include "rewrite/rewriteHandler.h"
30 #include "rewrite/rewriteManip.h"
31 #include "rewrite/rewriteSupport.h"
32 #include "utils/acl.h"
33 #include "utils/builtins.h"
34 #include "utils/lsyscache.h"
35 #include "utils/rel.h"
36 #include "utils/syscache.h"
37 
38 static void checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc);
39 
40 /*---------------------------------------------------------------------
41  * DefineVirtualRelation
42  *
43  * Create a view relation and use the rules system to store the query
44  * for the view.
45  *
46  * EventTriggerAlterTableStart must have been called already.
47  *---------------------------------------------------------------------
48  */
49 static ObjectAddress
50 DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
51  List *options, Query *viewParse)
52 {
53  Oid viewOid;
54  LOCKMODE lockmode;
55  CreateStmt *createStmt = makeNode(CreateStmt);
56  List *attrList;
57  ListCell *t;
58 
59  /*
60  * create a list of ColumnDef nodes based on the names and types of the
61  * (non-junk) targetlist items from the view's SELECT list.
62  */
63  attrList = NIL;
64  foreach(t, tlist)
65  {
66  TargetEntry *tle = (TargetEntry *) lfirst(t);
67 
68  if (!tle->resjunk)
69  {
70  ColumnDef *def = makeColumnDef(tle->resname,
71  exprType((Node *) tle->expr),
72  exprTypmod((Node *) tle->expr),
73  exprCollation((Node *) tle->expr));
74 
75  /*
76  * It's possible that the column is of a collatable type but the
77  * collation could not be resolved, so double-check.
78  */
79  if (type_is_collatable(exprType((Node *) tle->expr)))
80  {
81  if (!OidIsValid(def->collOid))
82  ereport(ERROR,
83  (errcode(ERRCODE_INDETERMINATE_COLLATION),
84  errmsg("could not determine which collation to use for view column \"%s\"",
85  def->colname),
86  errhint("Use the COLLATE clause to set the collation explicitly.")));
87  }
88  else
89  Assert(!OidIsValid(def->collOid));
90 
91  attrList = lappend(attrList, def);
92  }
93  }
94 
95  /*
96  * Look up, check permissions on, and lock the creation namespace; also
97  * check for a preexisting view with the same name. This will also set
98  * relation->relpersistence to RELPERSISTENCE_TEMP if the selected
99  * namespace is temporary.
100  */
101  lockmode = replace ? AccessExclusiveLock : NoLock;
102  (void) RangeVarGetAndCheckCreationNamespace(relation, lockmode, &viewOid);
103 
104  if (OidIsValid(viewOid) && replace)
105  {
106  Relation rel;
108  List *atcmds = NIL;
109  AlterTableCmd *atcmd;
110  ObjectAddress address;
111 
112  /* Relation is already locked, but we must build a relcache entry. */
113  rel = relation_open(viewOid, NoLock);
114 
115  /* Make sure it *is* a view. */
116  if (rel->rd_rel->relkind != RELKIND_VIEW)
117  ereport(ERROR,
118  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
119  errmsg("\"%s\" is not a view",
120  RelationGetRelationName(rel))));
121 
122  /* Also check it's not in use already */
123  CheckTableNotInUse(rel, "CREATE OR REPLACE VIEW");
124 
125  /*
126  * Due to the namespace visibility rules for temporary objects, we
127  * should only end up replacing a temporary view with another
128  * temporary view, and similarly for permanent views.
129  */
130  Assert(relation->relpersistence == rel->rd_rel->relpersistence);
131 
132  /*
133  * Create a tuple descriptor to compare against the existing view, and
134  * verify that the old column list is an initial prefix of the new
135  * column list.
136  */
137  descriptor = BuildDescForRelation(attrList);
139 
140  /*
141  * If new attributes have been added, we must add pg_attribute entries
142  * for them. It is convenient (although overkill) to use the ALTER
143  * TABLE ADD COLUMN infrastructure for this.
144  *
145  * Note that we must do this before updating the query for the view,
146  * since the rules system requires that the correct view columns be in
147  * place when defining the new rules.
148  *
149  * Also note that ALTER TABLE doesn't run parse transformation on
150  * AT_AddColumnToView commands. The ColumnDef we supply must be ready
151  * to execute as-is.
152  */
153  if (list_length(attrList) > rel->rd_att->natts)
154  {
155  ListCell *c;
156  int skip = rel->rd_att->natts;
157 
158  foreach(c, attrList)
159  {
160  if (skip > 0)
161  {
162  skip--;
163  continue;
164  }
165  atcmd = makeNode(AlterTableCmd);
166  atcmd->subtype = AT_AddColumnToView;
167  atcmd->def = (Node *) lfirst(c);
168  atcmds = lappend(atcmds, atcmd);
169  }
170 
171  /* EventTriggerAlterTableStart called by ProcessUtilitySlow */
172  AlterTableInternal(viewOid, atcmds, true);
173 
174  /* Make the new view columns visible */
176  }
177 
178  /*
179  * Update the query for the view.
180  *
181  * Note that we must do this before updating the view options, because
182  * the new options may not be compatible with the old view query (for
183  * example if we attempt to add the WITH CHECK OPTION, we require that
184  * the new view be automatically updatable, but the old view may not
185  * have been).
186  */
187  StoreViewQuery(viewOid, viewParse, replace);
188 
189  /* Make the new view query visible */
191 
192  /*
193  * Update the view's options.
194  *
195  * The new options list replaces the existing options list, even if
196  * it's empty.
197  */
198  atcmd = makeNode(AlterTableCmd);
199  atcmd->subtype = AT_ReplaceRelOptions;
200  atcmd->def = (Node *) options;
201  atcmds = list_make1(atcmd);
202 
203  /* EventTriggerAlterTableStart called by ProcessUtilitySlow */
204  AlterTableInternal(viewOid, atcmds, true);
205 
206  /*
207  * There is very little to do here to update the view's dependencies.
208  * Most view-level dependency relationships, such as those on the
209  * owner, schema, and associated composite type, aren't changing.
210  * Because we don't allow changing type or collation of an existing
211  * view column, those dependencies of the existing columns don't
212  * change either, while the AT_AddColumnToView machinery took care of
213  * adding such dependencies for new view columns. The dependencies of
214  * the view's query could have changed arbitrarily, but that was dealt
215  * with inside StoreViewQuery. What remains is only to check that
216  * view replacement is allowed when we're creating an extension.
217  */
218  ObjectAddressSet(address, RelationRelationId, viewOid);
219 
220  recordDependencyOnCurrentExtension(&address, true);
221 
222  /*
223  * Seems okay, so return the OID of the pre-existing view.
224  */
225  relation_close(rel, NoLock); /* keep the lock! */
226 
227  return address;
228  }
229  else
230  {
231  ObjectAddress address;
232 
233  /*
234  * Set the parameters for keys/inheritance etc. All of these are
235  * uninteresting for views...
236  */
237  createStmt->relation = relation;
238  createStmt->tableElts = attrList;
239  createStmt->inhRelations = NIL;
240  createStmt->constraints = NIL;
241  createStmt->options = options;
242  createStmt->oncommit = ONCOMMIT_NOOP;
243  createStmt->tablespacename = NULL;
244  createStmt->if_not_exists = false;
245 
246  /*
247  * Create the relation (this will error out if there's an existing
248  * view, so we don't need more code to complain if "replace" is
249  * false).
250  */
251  address = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid, NULL,
252  NULL);
253  Assert(address.objectId != InvalidOid);
254 
255  /* Make the new view relation visible */
257 
258  /* Store the query for the view */
259  StoreViewQuery(address.objectId, viewParse, replace);
260 
261  return address;
262  }
263 }
264 
265 /*
266  * Verify that tupledesc associated with proposed new view definition
267  * matches tupledesc of old view. This is basically a cut-down version
268  * of equalTupleDescs(), with code added to generate specific complaints.
269  * Also, we allow the new tupledesc to have more columns than the old.
270  */
271 static void
273 {
274  int i;
275 
276  if (newdesc->natts < olddesc->natts)
277  ereport(ERROR,
278  (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
279  errmsg("cannot drop columns from view")));
280 
281  for (i = 0; i < olddesc->natts; i++)
282  {
283  Form_pg_attribute newattr = TupleDescAttr(newdesc, i);
284  Form_pg_attribute oldattr = TupleDescAttr(olddesc, i);
285 
286  /* XXX msg not right, but we don't support DROP COL on view anyway */
287  if (newattr->attisdropped != oldattr->attisdropped)
288  ereport(ERROR,
289  (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
290  errmsg("cannot drop columns from view")));
291 
292  if (strcmp(NameStr(newattr->attname), NameStr(oldattr->attname)) != 0)
293  ereport(ERROR,
294  (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
295  errmsg("cannot change name of view column \"%s\" to \"%s\"",
296  NameStr(oldattr->attname),
297  NameStr(newattr->attname)),
298  errhint("Use ALTER VIEW ... RENAME COLUMN ... to change name of view column instead.")));
299 
300  /*
301  * We cannot allow type, typmod, or collation to change, since these
302  * properties may be embedded in Vars of other views/rules referencing
303  * this one. Other column attributes can be ignored.
304  */
305  if (newattr->atttypid != oldattr->atttypid ||
306  newattr->atttypmod != oldattr->atttypmod)
307  ereport(ERROR,
308  (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
309  errmsg("cannot change data type of view column \"%s\" from %s to %s",
310  NameStr(oldattr->attname),
311  format_type_with_typemod(oldattr->atttypid,
312  oldattr->atttypmod),
313  format_type_with_typemod(newattr->atttypid,
314  newattr->atttypmod))));
315 
316  /*
317  * At this point, attcollations should be both valid or both invalid,
318  * so applying get_collation_name unconditionally should be fine.
319  */
320  if (newattr->attcollation != oldattr->attcollation)
321  ereport(ERROR,
322  (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
323  errmsg("cannot change collation of view column \"%s\" from \"%s\" to \"%s\"",
324  NameStr(oldattr->attname),
325  get_collation_name(oldattr->attcollation),
326  get_collation_name(newattr->attcollation))));
327  }
328 
329  /*
330  * We ignore the constraint fields. The new view desc can't have any
331  * constraints, and the only ones that could be on the old view are
332  * defaults, which we are happy to leave in place.
333  */
334 }
335 
336 static void
337 DefineViewRules(Oid viewOid, Query *viewParse, bool replace)
338 {
339  /*
340  * Set up the ON SELECT rule. Since the query has already been through
341  * parse analysis, we use DefineQueryRewrite() directly.
342  */
344  viewOid,
345  NULL,
346  CMD_SELECT,
347  true,
348  replace,
349  list_make1(viewParse));
350 
351  /*
352  * Someday: automatic ON INSERT, etc
353  */
354 }
355 
356 /*---------------------------------------------------------------
357  * UpdateRangeTableOfViewParse
358  *
359  * Update the range table of the given parsetree.
360  * This update consists of adding two new entries IN THE BEGINNING
361  * of the range table (otherwise the rule system will die a slow,
362  * horrible and painful death, and we do not want that now, do we?)
363  * one for the OLD relation and one for the NEW one (both of
364  * them refer in fact to the "view" relation).
365  *
366  * Of course we must also increase the 'varnos' of all the Var nodes
367  * by 2...
368  *
369  * These extra RT entries are not actually used in the query,
370  * except for run-time locking.
371  *---------------------------------------------------------------
372  */
373 static Query *
375 {
376  Relation viewRel;
377  List *new_rt;
378  ParseNamespaceItem *nsitem;
379  RangeTblEntry *rt_entry1,
380  *rt_entry2;
381  RTEPermissionInfo *rte_perminfo1;
382  ParseState *pstate;
383  ListCell *lc;
384 
385  /*
386  * Make a copy of the given parsetree. It's not so much that we don't
387  * want to scribble on our input, it's that the parser has a bad habit of
388  * outputting multiple links to the same subtree for constructs like
389  * BETWEEN, and we mustn't have OffsetVarNodes increment the varno of a
390  * Var node twice. copyObject will expand any multiply-referenced subtree
391  * into multiple copies.
392  */
393  viewParse = copyObject(viewParse);
394 
395  /* Create a dummy ParseState for addRangeTableEntryForRelation */
396  pstate = make_parsestate(NULL);
397 
398  /* need to open the rel for addRangeTableEntryForRelation */
399  viewRel = relation_open(viewOid, AccessShareLock);
400 
401  /*
402  * Create the 2 new range table entries and form the new range table...
403  * OLD first, then NEW....
404  */
405  nsitem = addRangeTableEntryForRelation(pstate, viewRel,
407  makeAlias("old", NIL),
408  false, false);
409  rt_entry1 = nsitem->p_rte;
410  rte_perminfo1 = nsitem->p_perminfo;
411  nsitem = addRangeTableEntryForRelation(pstate, viewRel,
413  makeAlias("new", NIL),
414  false, false);
415  rt_entry2 = nsitem->p_rte;
416 
417  /*
418  * Add only the "old" RTEPermissionInfo at the head of view query's list
419  * and update the other RTEs' perminfoindex accordingly. When rewriting a
420  * query on the view, ApplyRetrieveRule() will transfer the view
421  * relation's permission details into this RTEPermissionInfo. That's
422  * needed because the view's RTE itself will be transposed into a subquery
423  * RTE that can't carry the permission details; see the code stanza toward
424  * the end of ApplyRetrieveRule() for how that's done.
425  */
426  viewParse->rteperminfos = lcons(rte_perminfo1, viewParse->rteperminfos);
427  foreach(lc, viewParse->rtable)
428  {
429  RangeTblEntry *rte = lfirst(lc);
430 
431  if (rte->perminfoindex > 0)
432  rte->perminfoindex += 1;
433  }
434 
435  /*
436  * Also make the "new" RTE's RTEPermissionInfo undiscoverable. This is a
437  * bit of a hack given that all the non-child RTE_RELATION entries really
438  * should have a RTEPermissionInfo, but this dummy "new" RTE is going to
439  * go away anyway in the very near future.
440  */
441  rt_entry2->perminfoindex = 0;
442 
443  new_rt = lcons(rt_entry1, lcons(rt_entry2, viewParse->rtable));
444 
445  viewParse->rtable = new_rt;
446 
447  /*
448  * Now offset all var nodes by 2, and jointree RT indexes too.
449  */
450  OffsetVarNodes((Node *) viewParse, 2, 0);
451 
453 
454  return viewParse;
455 }
456 
457 /*
458  * DefineView
459  * Execute a CREATE VIEW command.
460  */
462 DefineView(ViewStmt *stmt, const char *queryString,
463  int stmt_location, int stmt_len)
464 {
465  RawStmt *rawstmt;
466  Query *viewParse;
467  RangeVar *view;
468  ListCell *cell;
469  bool check_option;
470  ObjectAddress address;
471 
472  /*
473  * Run parse analysis to convert the raw parse tree to a Query. Note this
474  * also acquires sufficient locks on the source table(s).
475  */
476  rawstmt = makeNode(RawStmt);
477  rawstmt->stmt = stmt->query;
478  rawstmt->stmt_location = stmt_location;
479  rawstmt->stmt_len = stmt_len;
480 
481  viewParse = parse_analyze_fixedparams(rawstmt, queryString, NULL, 0, NULL);
482 
483  /*
484  * The grammar should ensure that the result is a single SELECT Query.
485  * However, it doesn't forbid SELECT INTO, so we have to check for that.
486  */
487  if (!IsA(viewParse, Query))
488  elog(ERROR, "unexpected parse analysis result");
489  if (viewParse->utilityStmt != NULL &&
490  IsA(viewParse->utilityStmt, CreateTableAsStmt))
491  ereport(ERROR,
492  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
493  errmsg("views must not contain SELECT INTO")));
494  if (viewParse->commandType != CMD_SELECT)
495  elog(ERROR, "unexpected parse analysis result");
496 
497  /*
498  * Check for unsupported cases. These tests are redundant with ones in
499  * DefineQueryRewrite(), but that function will complain about a bogus ON
500  * SELECT rule, and we'd rather the message complain about a view.
501  */
502  if (viewParse->hasModifyingCTE)
503  ereport(ERROR,
504  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
505  errmsg("views must not contain data-modifying statements in WITH")));
506 
507  /*
508  * If the user specified the WITH CHECK OPTION, add it to the list of
509  * reloptions.
510  */
511  if (stmt->withCheckOption == LOCAL_CHECK_OPTION)
512  stmt->options = lappend(stmt->options,
513  makeDefElem("check_option",
514  (Node *) makeString("local"), -1));
515  else if (stmt->withCheckOption == CASCADED_CHECK_OPTION)
516  stmt->options = lappend(stmt->options,
517  makeDefElem("check_option",
518  (Node *) makeString("cascaded"), -1));
519 
520  /*
521  * Check that the view is auto-updatable if WITH CHECK OPTION was
522  * specified.
523  */
524  check_option = false;
525 
526  foreach(cell, stmt->options)
527  {
528  DefElem *defel = (DefElem *) lfirst(cell);
529 
530  if (strcmp(defel->defname, "check_option") == 0)
531  check_option = true;
532  }
533 
534  /*
535  * If the check option is specified, look to see if the view is actually
536  * auto-updatable or not.
537  */
538  if (check_option)
539  {
540  const char *view_updatable_error =
541  view_query_is_auto_updatable(viewParse, true);
542 
543  if (view_updatable_error)
544  ereport(ERROR,
545  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
546  errmsg("WITH CHECK OPTION is supported only on automatically updatable views"),
547  errhint("%s", _(view_updatable_error))));
548  }
549 
550  /*
551  * If a list of column names was given, run through and insert these into
552  * the actual query tree. - thomas 2000-03-08
553  */
554  if (stmt->aliases != NIL)
555  {
556  ListCell *alist_item = list_head(stmt->aliases);
557  ListCell *targetList;
558 
559  foreach(targetList, viewParse->targetList)
560  {
561  TargetEntry *te = lfirst_node(TargetEntry, targetList);
562 
563  /* junk columns don't get aliases */
564  if (te->resjunk)
565  continue;
566  te->resname = pstrdup(strVal(lfirst(alist_item)));
567  alist_item = lnext(stmt->aliases, alist_item);
568  if (alist_item == NULL)
569  break; /* done assigning aliases */
570  }
571 
572  if (alist_item != NULL)
573  ereport(ERROR,
574  (errcode(ERRCODE_SYNTAX_ERROR),
575  errmsg("CREATE VIEW specifies more column "
576  "names than columns")));
577  }
578 
579  /* Unlogged views are not sensible. */
580  if (stmt->view->relpersistence == RELPERSISTENCE_UNLOGGED)
581  ereport(ERROR,
582  (errcode(ERRCODE_SYNTAX_ERROR),
583  errmsg("views cannot be unlogged because they do not have storage")));
584 
585  /*
586  * If the user didn't explicitly ask for a temporary view, check whether
587  * we need one implicitly. We allow TEMP to be inserted automatically as
588  * long as the CREATE command is consistent with that --- no explicit
589  * schema name.
590  */
591  view = copyObject(stmt->view); /* don't corrupt original command */
592  if (view->relpersistence == RELPERSISTENCE_PERMANENT
593  && isQueryUsingTempRelation(viewParse))
594  {
595  view->relpersistence = RELPERSISTENCE_TEMP;
596  ereport(NOTICE,
597  (errmsg("view \"%s\" will be a temporary view",
598  view->relname)));
599  }
600 
601  /*
602  * Create the view relation
603  *
604  * NOTE: if it already exists and replace is false, the xact will be
605  * aborted.
606  */
607  address = DefineVirtualRelation(view, viewParse->targetList,
608  stmt->replace, stmt->options, viewParse);
609 
610  return address;
611 }
612 
613 /*
614  * Use the rules system to store the query for the view.
615  */
616 void
617 StoreViewQuery(Oid viewOid, Query *viewParse, bool replace)
618 {
619  /*
620  * The range table of 'viewParse' does not contain entries for the "OLD"
621  * and "NEW" relations. So... add them!
622  */
623  viewParse = UpdateRangeTableOfViewParse(viewOid, viewParse);
624 
625  /*
626  * Now create the rules associated with the view.
627  */
628  DefineViewRules(viewOid, viewParse, replace);
629 }
#define NameStr(name)
Definition: c.h:682
#define OidIsValid(objectId)
Definition: c.h:711
int errhint(const char *fmt,...)
Definition: elog.c:1153
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define _(x)
Definition: elog.c:90
#define ERROR
Definition: elog.h:35
#define NOTICE
Definition: elog.h:31
#define ereport(elevel,...)
Definition: elog.h:145
char * format_type_with_typemod(Oid type_oid, int32 typemod)
Definition: format_type.c:358
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
Definition: list.c:338
List * lcons(void *datum, List *list)
Definition: list.c:494
int LOCKMODE
Definition: lockdefs.h:26
#define NoLock
Definition: lockdefs.h:34
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define AccessShareLock
Definition: lockdefs.h:36
char * get_collation_name(Oid colloid)
Definition: lsyscache.c:1061
bool type_is_collatable(Oid typid)
Definition: lsyscache.c:3039
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:387
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:546
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
Definition: makefuncs.c:490
char * pstrdup(const char *in)
Definition: mcxt.c:1483
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
Definition: namespace.c:537
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:266
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:764
#define IsA(nodeptr, _type_)
Definition: nodes.h:168
#define copyObject(obj)
Definition: nodes.h:233
@ CMD_SELECT
Definition: nodes.h:265
#define makeNode(_type_)
Definition: nodes.h:165
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:43
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
bool isQueryUsingTempRelation(Query *query)
@ AT_ReplaceRelOptions
Definition: parsenodes.h:2021
@ AT_AddColumnToView
Definition: parsenodes.h:1982
@ CASCADED_CHECK_OPTION
Definition: parsenodes.h:3371
@ LOCAL_CHECK_OPTION
Definition: parsenodes.h:3370
Query * parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceText, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
Definition: analyze.c:106
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
static const struct exclude_list_item skip[]
Definition: pg_checksums.c:116
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:192
#define lfirst(lc)
Definition: pg_list.h:170
#define lfirst_node(type, lc)
Definition: pg_list.h:174
static int list_length(const List *l)
Definition: pg_list.h:150
#define NIL
Definition: pg_list.h:66
#define list_make1(x1)
Definition: pg_list.h:210
static ListCell * list_head(const List *l)
Definition: pg_list.h:126
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:341
static char ** options
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
char * c
@ ONCOMMIT_NOOP
Definition: primnodes.h:49
#define RelationGetRelationName(relation)
Definition: rel.h:535
ObjectAddress DefineQueryRewrite(const char *rulename, Oid event_relid, Node *event_qual, CmdType event_type, bool is_instead, bool replace, List *action)
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
Definition: rewriteManip.c:458
#define ViewSelectRuleName
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
AlterTableType subtype
Definition: parsenodes.h:2063
char * colname
Definition: parsenodes.h:690
Oid collOid
Definition: parsenodes.h:706
List * tableElts
Definition: parsenodes.h:2286
OnCommitAction oncommit
Definition: parsenodes.h:2294
List * options
Definition: parsenodes.h:2293
bool if_not_exists
Definition: parsenodes.h:2297
List * inhRelations
Definition: parsenodes.h:2287
RangeVar * relation
Definition: parsenodes.h:2285
char * tablespacename
Definition: parsenodes.h:2295
List * constraints
Definition: parsenodes.h:2292
char * defname
Definition: parsenodes.h:779
Definition: pg_list.h:52
Definition: nodes.h:118
RangeTblEntry * p_rte
Definition: parse_node.h:278
RTEPermissionInfo * p_perminfo
Definition: parse_node.h:280
List * rteperminfos
Definition: parsenodes.h:156
List * rtable
Definition: parsenodes.h:155
CmdType commandType
Definition: parsenodes.h:124
bool hasModifyingCTE
Definition: parsenodes.h:147
Node * utilityStmt
Definition: parsenodes.h:136
List * targetList
Definition: parsenodes.h:164
Index perminfoindex
Definition: parsenodes.h:1036
char * relname
Definition: primnodes.h:77
char relpersistence
Definition: primnodes.h:83
int stmt_len
Definition: parsenodes.h:1659
Node * stmt
Definition: parsenodes.h:1657
int stmt_location
Definition: parsenodes.h:1658
TupleDesc rd_att
Definition: rel.h:111
Form_pg_class rd_rel
Definition: rel.h:110
Expr * expr
Definition: primnodes.h:1555
char * resname
Definition: primnodes.h:1557
bool resjunk
Definition: primnodes.h:1562
bool replace
Definition: parsenodes.h:3380
List * options
Definition: parsenodes.h:3381
Node * query
Definition: parsenodes.h:3379
List * aliases
Definition: parsenodes.h:3378
RangeVar * view
Definition: parsenodes.h:3377
ViewCheckOption withCheckOption
Definition: parsenodes.h:3382
void CheckTableNotInUse(Relation rel, const char *stmt)
Definition: tablecmds.c:4004
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
Definition: tablecmds.c:662
void AlterTableInternal(Oid relid, List *cmds, bool recurse)
Definition: tablecmds.c:4121
TupleDesc BuildDescForRelation(List *schema)
Definition: tupdesc.c:786
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
String * makeString(char *str)
Definition: value.c:63
#define strVal(v)
Definition: value.h:82
static ObjectAddress DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, List *options, Query *viewParse)
Definition: view.c:50
static void checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
Definition: view.c:272
static void DefineViewRules(Oid viewOid, Query *viewParse, bool replace)
Definition: view.c:337
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: view.c:462
static Query * UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
Definition: view.c:374
void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace)
Definition: view.c:617
void CommandCounterIncrement(void)
Definition: xact.c:1077