83 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
84 errmsg(
"could not determine which collation to use for view column \"%s\"",
86 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
91 attrList =
lappend(attrList, def);
116 if (rel->
rd_rel->relkind != RELKIND_VIEW)
118 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
119 errmsg(
"\"%s\" is not a view",
168 atcmds =
lappend(atcmds, atcmd);
264 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
265 errmsg(
"cannot drop columns from view")));
267 for (i = 0; i < olddesc->
natts; i++)
273 if (newattr->attisdropped != oldattr->attisdropped)
275 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
276 errmsg(
"cannot drop columns from view")));
278 if (strcmp(
NameStr(newattr->attname),
NameStr(oldattr->attname)) != 0)
280 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
281 errmsg(
"cannot change name of view column \"%s\" to \"%s\"",
284 errhint(
"Use ALTER VIEW ... RENAME COLUMN ... to change name of view column instead.")));
286 if (newattr->atttypid != oldattr->atttypid ||
287 newattr->atttypmod != oldattr->atttypmod)
289 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
290 errmsg(
"cannot change data type of view column \"%s\" from %s to %s",
295 newattr->atttypmod))));
377 rt_entry1 = nsitem->
p_rte;
382 rt_entry2 = nsitem->
p_rte;
390 viewParse->
rtable = new_rt;
408 int stmt_location,
int stmt_len)
429 viewParse =
parse_analyze(rawstmt, queryString, NULL, 0, NULL);
436 elog(
ERROR,
"unexpected parse analysis result");
440 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
441 errmsg(
"views must not contain SELECT INTO")));
443 elog(
ERROR,
"unexpected parse analysis result");
452 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
453 errmsg(
"views must not contain data-modifying statements in WITH")));
472 check_option =
false;
478 if (strcmp(defel->
defname,
"check_option") == 0)
488 const char *view_updatable_error =
491 if (view_updatable_error)
493 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
494 errmsg(
"WITH CHECK OPTION is supported only on automatically updatable views"),
495 errhint(
"%s",
_(view_updatable_error))));
516 if (alist_item == NULL)
520 if (alist_item != NULL)
522 (
errcode(ERRCODE_SYNTAX_ERROR),
523 errmsg(
"CREATE VIEW specifies more column " 524 "names than columns")));
530 (
errcode(ERRCODE_SYNTAX_ERROR),
531 errmsg(
"views cannot be unlogged because they do not have storage")));
545 (
errmsg(
"view \"%s\" will be a temporary view",
Value * makeString(char *str)
#define IsA(nodeptr, _type_)
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
int errhint(const char *fmt,...)
bool isQueryUsingTempRelation(Query *query)
static ListCell * lnext(const List *l, const ListCell *c)
int32 exprTypmod(const Node *expr)
#define TupleDescAttr(tupdesc, i)
char * pstrdup(const char *in)
static const struct exclude_list_item skip[]
int errcode(int sqlerrcode)
#define ViewSelectRuleName
static void checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
#define OidIsValid(objectId)
DefElem * makeDefElem(char *name, Node *arg, int location)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
ParseState * make_parsestate(ParseState *parentParseState)
Alias * makeAlias(const char *aliasname, List *colnames)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
#define lfirst_node(type, lc)
#define RelationGetRelationName(relation)
static ListCell * list_head(const List *l)
FormData_pg_attribute * Form_pg_attribute
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
void CheckTableNotInUse(Relation rel, const char *stmt)
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
List * lappend(List *list, void *datum)
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
void CommandCounterIncrement(void)
void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace)
#define ereport(elevel,...)
Query * parse_analyze(RawStmt *parseTree, const char *sourceText, Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
static Query * UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
List * lcons(void *datum, List *list)
void relation_close(Relation relation, LOCKMODE lockmode)
#define Assert(condition)
Oid exprType(const Node *expr)
static int list_length(const List *l)
Oid exprCollation(const Node *expr)
static ObjectAddress DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, List *options, Query *viewParse)
#define ObjectAddressSet(addr, class_id, object_id)
void AlterTableInternal(Oid relid, List *cmds, bool recurse)
#define AccessExclusiveLock
int errmsg(const char *fmt,...)
ViewCheckOption withCheckOption
TupleDesc BuildDescForRelation(List *schema)
static void DefineViewRules(Oid viewOid, Query *viewParse, bool replace)
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
bool type_is_collatable(Oid typid)
ObjectAddress DefineQueryRewrite(const char *rulename, Oid event_relid, Node *event_qual, CmdType event_type, bool is_instead, bool replace, List *action)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)