The target list order must be exactly the same as
that in which the columns appear in the table associated
- with the composite type.
+ with the composite type. (Naming the columns, as we did above,
+ is irrelevant to the system.)
there are some unpleasant restrictions on how functions returning
composite types can be used. Briefly, when calling a function that
returns a row, we cannot retrieve the entire row. We must either
- project a single attribute out of the row or pass the entire row into
+ extract a single attribute out of the row or pass the entire row into
another function. (Trying to display the entire row value will yield
a meaningless number.) For example,
-SELECT name(new_emp());
+SELECT (new_emp()).name;
name
------
None
+
+
+ We need the extra parentheses to keep the parser from getting confused:
+
+
+SELECT new_emp().name;
+ERROR: parser: parse error at or near "."
- This example makes use of the
- function notation for projecting attributes. The simple way
- to explain this is that we can usually use the
+ Another approach is to use
+ functional notation for extracting attributes. The simple way
+ to explain this is that we can use the
notations attribute(table)> and table.attribute>
interchangeably:
+SELECT name(new_emp());
+
+
+
+ name
+------
+ None
+
+
+
--
-- this is the same as:
- The reason why, in general, we must use the function
- syntax for projecting attributes of function return
- values is that the parser just doesn't understand
- the dot syntax for projection when combined
- with function calls.
-
-
-SELECT new_emp().name AS nobody;
-ERROR: parser: parse error at or near "."
-
-
-
Another way to use a function returning a row result is to declare a
second function accepting a row type parameter, and pass the function
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.56 2002/03/06 06:09:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.57 2002/03/21 16:00:29 tgl Exp $
*
* NOTES
* See acl.h.
foreach(i, stmt->objects)
{
- char *relname = strVal(lfirst(i));
+ char *relname = ((RangeVar *) lfirst(i))->relname;
Relation relation;
HeapTuple tuple;
Form_pg_class pg_class_tuple;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.189 2002/03/20 19:43:34 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.190 2002/03/21 16:00:29 tgl Exp $
*
*
* INTERFACE ROUTINES
/*
* Transform raw parsetree to executable expression.
*/
- expr = transformExpr(pstate, cdef->raw_expr, EXPR_COLUMN_FIRST);
+ expr = transformExpr(pstate, cdef->raw_expr);
/*
* Make sure it yields a boolean result.
/*
* Transform raw parsetree to executable expression.
*/
- expr = transformExpr(pstate, raw_default, EXPR_COLUMN_FIRST);
+ expr = transformExpr(pstate, raw_default);
/*
* Make sure default expr does not refer to any vars.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.161 2002/03/14 22:44:50 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.162 2002/03/21 16:00:31 tgl Exp $
*
* NOTES
* The PerformAddAttribute() code, like most of the relation
#include "catalog/pg_type.h"
#include "commands/command.h"
#include "commands/trigger.h"
-#include "commands/defrem.h" /* For add constraint unique, primary */
+#include "commands/defrem.h"
#include "executor/execdefs.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "parser/parse_expr.h"
#include "parser/parse_oper.h"
#include "parser/parse_relation.h"
-#include "parser/analyze.h" /* For add constraint unique, primary */
+#include "parser/analyze.h"
+#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
* Convert the A_EXPR in raw_expr into an
* EXPR
*/
- expr = transformExpr(pstate, constr->raw_expr,
- EXPR_COLUMN_FIRST);
+ expr = transformExpr(pstate, constr->raw_expr);
/*
* Make sure it yields a boolean result.
List *list;
int count;
- if (is_temp_rel_name(fkconstraint->pktable_name) &&
+ if (is_temp_rel_name(fkconstraint->pktable->relname) &&
!is_temp_rel_name(relationName))
elog(ERROR, "ALTER TABLE / ADD CONSTRAINT: Unable to reference temporary table from permanent table constraint.");
* someone doesn't delete rows out from under us.
*/
- pkrel = heap_openr(fkconstraint->pktable_name, AccessExclusiveLock);
+ pkrel = heap_openr(fkconstraint->pktable->relname, AccessExclusiveLock);
if (pkrel->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "referenced table \"%s\" not a relation",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
heap_close(pkrel, NoLock);
/*
else
trig.tgargs[0] = "";
trig.tgargs[1] = (char *) relationName;
- trig.tgargs[2] = fkconstraint->pktable_name;
+ trig.tgargs[2] = fkconstraint->pktable->relname;
trig.tgargs[3] = fkconstraint->match_type;
count = 4;
foreach(list, fkconstraint->fk_attrs)
* at a time
*/
- foreach(p, lockstmt->rellist)
+ foreach(p, lockstmt->relations)
{
- char *relname = strVal(lfirst(p));
+ RangeVar *relation = lfirst(p);
+ char *relname = relation->relname;
int aclresult;
Relation rel;
relation_close(rel, NoLock); /* close rel, keep lock */
}
}
+
+
+/*
+ * CREATE SCHEMA
+ */
+void
+CreateSchemaCommand(CreateSchemaStmt *stmt)
+{
+ const char *schemaName = stmt->schemaname;
+ const char *authId = stmt->authid;
+ List *parsetree_list;
+ List *parsetree_item;
+ const char *owner_name;
+ Oid owner_userid;
+ Oid saved_userid;
+
+ saved_userid = GetUserId();
+
+ if (!authId)
+ {
+ owner_userid = saved_userid;
+ owner_name = GetUserName(owner_userid);
+ }
+ else if (superuser())
+ {
+ owner_name = authId;
+ /* The following will error out if user does not exist */
+ owner_userid = get_usesysid(owner_name);
+ /*
+ * Set the current user to the requested authorization so
+ * that objects created in the statement have the requested
+ * owner. (This will revert to session user on error or at
+ * the end of this routine.)
+ */
+ SetUserId(owner_userid);
+ }
+ else /* not superuser */
+ {
+ owner_userid = saved_userid;
+ owner_name = GetUserName(owner_userid);
+ if (strcmp(authId, owner_name) != 0)
+ elog(ERROR, "CREATE SCHEMA: permission denied"
+ "\n\t\"%s\" is not a superuser, so cannot create a schema for \"%s\"",
+ owner_name, authId);
+ }
+
+ /* FIXME FENN: Create the schema here */
+ (void) schemaName; /* suppress compiler warning for now... */
+
+ /*
+ * Let commands in the schema-element-list know about the schema
+ */
+ CommandCounterIncrement();
+
+ /*
+ * Examine the list of commands embedded in the CREATE SCHEMA command,
+ * and reorganize them into a sequentially executable order with no
+ * forward references. Note that the result is still a list of raw
+ * parsetrees in need of parse analysis --- we cannot, in general,
+ * run analyze.c on one statement until we have actually executed the
+ * prior ones.
+ */
+ parsetree_list = analyzeCreateSchemaStmt(stmt);
+
+ /*
+ * Analyze and execute each command contained in the CREATE SCHEMA
+ */
+ foreach(parsetree_item, parsetree_list)
+ {
+ Node *parsetree = (Node *) lfirst(parsetree_item);
+ List *querytree_list,
+ *querytree_item;
+
+ querytree_list = parse_analyze(parsetree, NULL);
+
+ foreach(querytree_item, querytree_list)
+ {
+ Query *querytree = (Query *) lfirst(querytree_item);
+
+ /* schemas should contain only utility stmts */
+ Assert(querytree->commandType == CMD_UTILITY);
+ /* do this step */
+ ProcessUtility(querytree->utilityStmt, None, NULL);
+ /* make sure later steps can see the object created here */
+ CommandCounterIncrement();
+ }
+ }
+
+ /* Reset current user */
+ SetUserId(saved_userid);
+}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.88 2002/03/20 19:43:42 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.89 2002/03/21 16:00:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Truncate relname to appropriate length (probably a waste of time,
* as parser should have done this already).
*/
- StrNCpy(relname, stmt->relname, NAMEDATALEN);
+ StrNCpy(relname, (stmt->relation)->relname, NAMEDATALEN);
/*
* Merge domain attributes into the known columns before processing table
* Look up inheritance ancestors and generate relation schema,
* including inherited attributes.
*/
- schema = MergeAttributes(schema, stmt->inhRelnames, stmt->istemp,
- &inheritOids, &old_constraints, &parentHasOids);
+ schema = MergeAttributes(schema, stmt->inhRelations,
+ stmt->relation->istemp,
+ &inheritOids, &old_constraints, &parentHasOids);
numberOfAttributes = length(schema);
if (numberOfAttributes <= 0)
relationId = heap_create_with_catalog(relname, descriptor,
relkind,
stmt->hasoids || parentHasOids,
- stmt->istemp,
+ stmt->relation->istemp,
allowSystemTableMods);
StoreCatalogInheritance(relationId, inheritOids);
/*
* Reject duplicate names in the list of parents, too.
+ *
+ * XXX needs to be smarter about schema-qualified table names.
*/
foreach(entry, supers)
{
foreach(rest, lnext(entry))
{
- if (strcmp(strVal(lfirst(entry)), strVal(lfirst(rest))) == 0)
+ if (strcmp(((RangeVar *) lfirst(entry))->relname,
+ ((RangeVar *) lfirst(rest))->relname) == 0)
elog(ERROR, "CREATE TABLE: inherited relation \"%s\" duplicated",
- strVal(lfirst(entry)));
+ ((RangeVar *) lfirst(entry))->relname);
}
}
child_attno = 0;
foreach(entry, supers)
{
- char *name = strVal(lfirst(entry));
+ char *name = ((RangeVar *) lfirst(entry))->relname;
Relation relation;
TupleDesc tupleDesc;
TupleConstr *constr;
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994-5, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.71 2002/03/12 00:51:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.72 2002/03/21 16:00:32 tgl Exp $
*
*/
appendStringInfo(str, " on %s",
stringStringInfo(rte->relname));
- if (strcmp(rte->eref->relname, rte->relname) != 0)
+ if (strcmp(rte->eref->aliasname, rte->relname) != 0)
appendStringInfo(str, " %s",
- stringStringInfo(rte->eref->relname));
+ stringStringInfo(rte->eref->aliasname));
}
break;
case T_SubqueryScan:
es->rtable);
appendStringInfo(str, " %s",
- stringStringInfo(rte->eref->relname));
+ stringStringInfo(rte->eref->aliasname));
}
break;
default:
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.71 2002/03/15 19:20:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.72 2002/03/21 16:00:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
case SEQ_COL_NAME:
typnam->name = "name";
coldef->colname = "sequence_name";
- namestrcpy(&name, seq->seqname);
+ namestrcpy(&name, seq->sequence->relname);
value[i - 1] = NameGetDatum(&name);
break;
case SEQ_COL_LASTVAL:
stmt->tableElts = lappend(stmt->tableElts, coldef);
}
- stmt->relname = seq->seqname;
- stmt->inhRelnames = NIL;
+ stmt->relation = seq->sequence;
+ stmt->inhRelations = NIL;
stmt->constraints = NIL;
- stmt->istemp = seq->istemp;
stmt->hasoids = false;
DefineRelation(stmt, RELKIND_SEQUENCE);
- rel = heap_openr(seq->seqname, AccessExclusiveLock);
+ rel = heap_openr(seq->sequence->relname, AccessExclusiveLock);
tupDesc = RelationGetDescr(rel);
/* Initialize first page of relation with special magic number */
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.105 2002/03/08 04:37:14 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.106 2002/03/21 16:00:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
char *constrname = "";
Oid constrrelid = InvalidOid;
- if (!allowSystemTableMods && IsSystemRelationName(stmt->relname))
- elog(ERROR, "CreateTrigger: can't create trigger for system relation %s", stmt->relname);
+ if (!allowSystemTableMods && IsSystemRelationName(stmt->relation->relname))
+ elog(ERROR, "CreateTrigger: can't create trigger for system relation %s",
+ stmt->relation->relname);
- if (pg_aclcheck(stmt->relname, GetUserId(),
+ if (pg_aclcheck(stmt->relation->relname, GetUserId(),
stmt->isconstraint ? ACL_REFERENCES : ACL_TRIGGER)
!= ACLCHECK_OK)
elog(ERROR, "permission denied");
stmt->trigname = constrtrigname;
sprintf(constrtrigname, "RI_ConstraintTrigger_%u", newoid());
- if (strcmp(stmt->constrrelname, "") == 0)
+ if (stmt->constrrel == NULL)
constrrelid = InvalidOid;
else
{
* NoLock is probably sufficient here, since we're only
* interested in getting the relation's OID...
*/
- rel = heap_openr(stmt->constrrelname, NoLock);
+ rel = heap_openr(stmt->constrrel->relname, NoLock);
constrrelid = rel->rd_id;
heap_close(rel, NoLock);
}
}
- rel = heap_openr(stmt->relname, AccessExclusiveLock);
+ rel = heap_openr(stmt->relation->relname, AccessExclusiveLock);
if (rel->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "CreateTrigger: relation \"%s\" is not a table",
- stmt->relname);
+ stmt->relation->relname);
TRIGGER_CLEAR_TYPE(tgtype);
if (stmt->before)
if (namestrcmp(&(pg_trigger->tgname), stmt->trigname) == 0)
elog(ERROR, "CreateTrigger: trigger %s already defined on relation %s",
- stmt->trigname, stmt->relname);
+ stmt->trigname, stmt->relation->relname);
found++;
}
systable_endscan(tgscan);
*/
pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
tuple = SearchSysCacheCopy(RELNAME,
- PointerGetDatum(stmt->relname),
+ PointerGetDatum(stmt->relation->relname),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "CreateTrigger: relation %s not found in pg_class",
- stmt->relname);
+ stmt->relation->relname);
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found + 1;
simple_heap_update(pgrel, &tuple->t_self, tuple);
int found = 0;
int tgfound = 0;
- if (!allowSystemTableMods && IsSystemRelationName(stmt->relname))
+ if (!allowSystemTableMods && IsSystemRelationName(stmt->relation->relname))
elog(ERROR, "DropTrigger: can't drop trigger for system relation %s",
- stmt->relname);
+ stmt->relation->relname);
- if (!pg_ownercheck(GetUserId(), stmt->relname, RELNAME))
- elog(ERROR, "%s: %s", stmt->relname,
+ if (!pg_ownercheck(GetUserId(), stmt->relation->relname, RELNAME))
+ elog(ERROR, "%s: %s", stmt->relation->relname,
aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
- rel = heap_openr(stmt->relname, AccessExclusiveLock);
+ rel = heap_openr(stmt->relation->relname, AccessExclusiveLock);
if (rel->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "DropTrigger: relation \"%s\" is not a table",
- stmt->relname);
+ stmt->relation->relname);
/*
* Search pg_trigger, delete target trigger, count remaining triggers
if (tgfound == 0)
elog(ERROR, "DropTrigger: there is no trigger %s on relation %s",
- stmt->trigname, stmt->relname);
+ stmt->trigname, stmt->relation->relname);
if (tgfound > 1)
elog(NOTICE, "DropTrigger: found (and deleted) %d triggers %s on relation %s",
- tgfound, stmt->trigname, stmt->relname);
+ tgfound, stmt->trigname, stmt->relation->relname);
/*
* Update relation's pg_class entry. Crucial side-effect: other
*/
pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
tuple = SearchSysCacheCopy(RELNAME,
- PointerGetDatum(stmt->relname),
+ PointerGetDatum(stmt->relation->relname),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "DropTrigger: relation %s not found in pg_class",
- stmt->relname);
+ stmt->relation->relname);
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found;
simple_heap_update(pgrel, &tuple->t_self, tuple);
{
Form_pg_trigger pg_trigger;
Relation refrel;
- DropTrigStmt stmt;
+ DropTrigStmt *stmt = makeNode(DropTrigStmt);
pg_trigger = (Form_pg_trigger) GETSTRUCT(tup);
- stmt.trigname = pstrdup(NameStr(pg_trigger->tgname));
+ stmt->trigname = pstrdup(NameStr(pg_trigger->tgname));
/* May as well grab AccessExclusiveLock, since DropTrigger will. */
refrel = heap_open(pg_trigger->tgrelid, AccessExclusiveLock);
- stmt.relname = pstrdup(RelationGetRelationName(refrel));
+ stmt->relation = makeNode(RangeVar);
+ /* XXX bogus: what about schema? */
+ stmt->relation->relname = pstrdup(RelationGetRelationName(refrel));
heap_close(refrel, NoLock);
- elog(NOTICE, "DROP TABLE implicitly drops referential integrity trigger from table \"%s\"", stmt.relname);
+ elog(NOTICE, "DROP TABLE implicitly drops referential integrity trigger from table \"%s\"",
+ stmt->relation->relname);
- DropTrigger(&stmt);
+ DropTrigger(stmt);
/*
* Need to do a command counter increment here to show up new
* FK table defined on the PK table).
*/
CommandCounterIncrement();
-
- pfree(stmt.relname);
- pfree(stmt.trigname);
}
systable_endscan(tgscan);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.217 2002/03/06 06:09:38 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.218 2002/03/21 16:00:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
- /* Convert vacrel, which is just a string, to a Name */
- if (vacstmt->vacrel)
+ /* Convert relname, which is just a string, to a Name */
+ if (vacstmt->relation)
{
- namestrcpy(&VacRel, vacstmt->vacrel);
+ namestrcpy(&VacRel, vacstmt->relation->relname);
VacRelName = &VacRel;
}
else
static void
vacuum_init(VacuumStmt *vacstmt)
{
- if (vacstmt->vacuum && vacstmt->vacrel == NULL)
+ if (vacstmt->vacuum && vacstmt->relation == NULL)
{
/*
* Compute the initially applicable OldestXmin and FreezeLimit
* row with info about the transaction IDs used, and try to truncate
* pg_clog.
*/
- if (vacstmt->vacuum && vacstmt->vacrel == NULL)
+ if (vacstmt->vacuum && vacstmt->relation == NULL)
{
vac_update_dbstats(MyDatabaseId,
initialOldestXmin, initialFreezeLimit);
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: view.c,v 1.58 2001/10/25 05:49:26 momjian Exp $
+ * $Id: view.c,v 1.59 2002/03/21 16:00:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
DefineVirtualRelation(char *relname, List *tlist)
{
CreateStmt *createStmt = makeNode(CreateStmt);
+ RangeVar *rel = makeNode(RangeVar);
List *attrList,
*t;
* now create the parameters for keys/inheritance etc. All of them are
* nil...
*/
- createStmt->relname = relname;
+ rel->relname = relname;
+ rel->schemaname = NULL; /* XXX wrong */
+ rel->istemp = false;
+ createStmt->relation = rel;
createStmt->tableElts = attrList;
- createStmt->inhRelnames = NIL;
+ createStmt->inhRelations = NIL;
createStmt->constraints = NIL;
- createStmt->istemp = false;
createStmt->hasoids = false;
/*
{
RuleStmt *rule;
char *rname;
- Attr *attr;
+ RangeVar *rel;
/*
* Create a RuleStmt that corresponds to the suitable rewrite rule
* args for DefineQueryRewrite();
*/
- rule = makeNode(RuleStmt);
rname = MakeRetrieveViewRuleName(viewName);
- attr = makeNode(Attr);
- attr->relname = pstrdup(viewName);
+ rel = makeNode(RangeVar);
+ rel->relname = pstrdup(viewName);
+ rel->inhOpt = INH_NO;
+ rel->alias = NULL;
+
+ rule = makeNode(RuleStmt);
+ rule->relation = rel;
rule->rulename = pstrdup(rname);
rule->whereClause = NULL;
rule->event = CMD_SELECT;
- rule->object = attr;
rule->instead = true;
rule->actions = makeList1(viewParse);
* table... OLD first, then NEW....
*/
rt_entry1 = addRangeTableEntry(NULL, viewName,
- makeAttr("*OLD*", NULL),
+ makeAlias("*OLD*", NIL),
false, false);
rt_entry2 = addRangeTableEntry(NULL, viewName,
- makeAttr("*NEW*", NULL),
+ makeAlias("*NEW*", NIL),
false, false);
/* Must override addRangeTableEntry's default access-check flags */
rt_entry1->checkForRead = false;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.152 2002/03/06 06:09:42 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.153 2002/03/21 16:00:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* create the "into" relation
*/
- intoName = parseTree->into;
+ intoName = parseTree->into->relname;
/*
* have to copy tupType to get rid of constraints
heap_create_with_catalog(intoName,
tupdesc,
RELKIND_RELATION, true,
- parseTree->isTemp,
+ parseTree->into->istemp,
allowSystemTableMods);
FreeTupleDesc(tupdesc);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.67 2002/02/27 19:34:59 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.68 2002/03/21 16:00:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* Modify the parsetree to be a cursor */
queryTree->isPortal = true;
- queryTree->into = pstrdup(name);
+ queryTree->into = makeNode(RangeVar);
+ queryTree->into->relname = pstrdup(name);
queryTree->isBinary = false;
/* Create the QueryDesc object and the executor state */
if (parseTree->isPortal)
{
isRetrieveIntoPortal = true;
- intoName = parseTree->into;
+ intoName = parseTree->into->relname;
parseTree->isBinary = false; /* */
return SPI_ERROR_CURSOR;
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.171 2002/03/20 19:43:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.172 2002/03/21 16:00:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return newnode;
}
-static Attr *
-_copyAttr(Attr *from)
-{
- Attr *newnode = makeNode(Attr);
-
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
- Node_Copy(from, newnode, attrs);
-
- return newnode;
-}
-
/* ----------------
* _copyOper
* ----------------
if (from->constr_name)
newnode->constr_name = pstrdup(from->constr_name);
- if (from->pktable_name)
- newnode->pktable_name = pstrdup(from->pktable_name);
+ Node_Copy(from, newnode, pktable);
Node_Copy(from, newnode, fk_attrs);
Node_Copy(from, newnode, pk_attrs);
if (from->match_type)
return newnode;
}
-static A_Const *
-_copyAConst(A_Const *from)
+static ColumnRef *
+_copyColumnRef(ColumnRef *from)
{
- A_Const *newnode = makeNode(A_Const);
+ ColumnRef *newnode = makeNode(ColumnRef);
- newnode->val = *((Value *) (copyObject(&(from->val))));
- Node_Copy(from, newnode, typename);
+ Node_Copy(from, newnode, fields);
+ Node_Copy(from, newnode, indirection);
return newnode;
}
-static ParamNo *
-_copyParamNo(ParamNo *from)
+static ParamRef *
+_copyParamRef(ParamRef *from)
{
- ParamNo *newnode = makeNode(ParamNo);
+ ParamRef *newnode = makeNode(ParamRef);
newnode->number = from->number;
- Node_Copy(from, newnode, typename);
+ Node_Copy(from, newnode, fields);
Node_Copy(from, newnode, indirection);
return newnode;
}
+static A_Const *
+_copyAConst(A_Const *from)
+{
+ A_Const *newnode = makeNode(A_Const);
+
+ newnode->val = *((Value *) (copyObject(&(from->val))));
+ Node_Copy(from, newnode, typename);
+
+ return newnode;
+}
+
static Ident *
_copyIdent(Ident *from)
{
Ident *newnode = makeNode(Ident);
- if (from->name)
- newnode->name = pstrdup(from->name);
- Node_Copy(from, newnode, indirection);
- newnode->isRel = from->isRel;
+ newnode->name = pstrdup(from->name);
return newnode;
}
return newnode;
}
+static ExprFieldSelect *
+_copyExprFieldSelect(ExprFieldSelect *from)
+{
+ ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
+
+ Node_Copy(from, newnode, arg);
+ Node_Copy(from, newnode, fields);
+ Node_Copy(from, newnode, indirection);
+
+ return newnode;
+}
+
static ResTarget *
_copyResTarget(ResTarget *from)
{
return newnode;
}
+static Alias *
+_copyAlias(Alias *from)
+{
+ Alias *newnode = makeNode(Alias);
+
+ if (from->aliasname)
+ newnode->aliasname = pstrdup(from->aliasname);
+ Node_Copy(from, newnode, colnames);
+
+ return newnode;
+}
+
static RangeVar *
_copyRangeVar(RangeVar *from)
{
RangeVar *newnode = makeNode(RangeVar);
+ if (from->catalogname)
+ newnode->catalogname = pstrdup(from->catalogname);
+ if (from->schemaname)
+ newnode->schemaname = pstrdup(from->schemaname);
if (from->relname)
newnode->relname = pstrdup(from->relname);
newnode->inhOpt = from->inhOpt;
- Node_Copy(from, newnode, name);
+ newnode->istemp = from->istemp;
+ Node_Copy(from, newnode, alias);
return newnode;
}
RangeSubselect *newnode = makeNode(RangeSubselect);
Node_Copy(from, newnode, subquery);
- Node_Copy(from, newnode, name);
+ Node_Copy(from, newnode, alias);
return newnode;
}
newnode->commandType = from->commandType;
Node_Copy(from, newnode, utilityStmt);
newnode->resultRelation = from->resultRelation;
- if (from->into)
- newnode->into = pstrdup(from->into);
+ Node_Copy(from, newnode, into);
newnode->isPortal = from->isPortal;
newnode->isBinary = from->isBinary;
- newnode->isTemp = from->isTemp;
newnode->hasAggs = from->hasAggs;
newnode->hasSubLinks = from->hasSubLinks;
newnode->originalQuery = from->originalQuery;
{
InsertStmt *newnode = makeNode(InsertStmt);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
Node_Copy(from, newnode, cols);
Node_Copy(from, newnode, targetList);
Node_Copy(from, newnode, selectStmt);
{
DeleteStmt *newnode = makeNode(DeleteStmt);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
Node_Copy(from, newnode, whereClause);
- newnode->inhOpt = from->inhOpt;
return newnode;
}
{
UpdateStmt *newnode = makeNode(UpdateStmt);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
Node_Copy(from, newnode, targetList);
Node_Copy(from, newnode, whereClause);
Node_Copy(from, newnode, fromClause);
- newnode->inhOpt = from->inhOpt;
return newnode;
}
SelectStmt *newnode = makeNode(SelectStmt);
Node_Copy(from, newnode, distinctClause);
- if (from->into)
- newnode->into = pstrdup(from->into);
- newnode->istemp = from->istemp;
+ Node_Copy(from, newnode, into);
Node_Copy(from, newnode, intoColNames);
Node_Copy(from, newnode, targetList);
Node_Copy(from, newnode, fromClause);
AlterTableStmt *newnode = makeNode(AlterTableStmt);
newnode->subtype = from->subtype;
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
- newnode->inhOpt = from->inhOpt;
+ Node_Copy(from, newnode, relation);
if (from->name)
newnode->name = pstrdup(from->name);
Node_Copy(from, newnode, def);
{
ClusterStmt *newnode = makeNode(ClusterStmt);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
if (from->indexname)
newnode->indexname = pstrdup(from->indexname);
CopyStmt *newnode = makeNode(CopyStmt);
newnode->binary = from->binary;
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
newnode->oids = from->oids;
newnode->direction = from->direction;
if (from->filename)
{
CreateStmt *newnode = makeNode(CreateStmt);
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
Node_Copy(from, newnode, tableElts);
- Node_Copy(from, newnode, inhRelnames);
+ Node_Copy(from, newnode, inhRelations);
Node_Copy(from, newnode, constraints);
- newnode->istemp = from->istemp;
newnode->hasoids = from->hasoids;
return newnode;
{
DropStmt *newnode = makeNode(DropStmt);
- Node_Copy(from, newnode, names);
+ Node_Copy(from, newnode, objects);
newnode->removeType = from->removeType;
newnode->behavior = from->behavior;
{
TruncateStmt *newnode = makeNode(TruncateStmt);
- newnode->relName = pstrdup(from->relName);
+ Node_Copy(from, newnode, relation);
return newnode;
}
CommentStmt *newnode = makeNode(CommentStmt);
newnode->objtype = from->objtype;
+ if (from->objschema)
+ newnode->objschema = pstrdup(from->objschema);
newnode->objname = pstrdup(from->objname);
if (from->objproperty)
newnode->objproperty = pstrdup(from->objproperty);
IndexStmt *newnode = makeNode(IndexStmt);
newnode->idxname = pstrdup(from->idxname);
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
newnode->accessMethod = pstrdup(from->accessMethod);
Node_Copy(from, newnode, indexParams);
Node_Copy(from, newnode, whereClause);
{
RenameStmt *newnode = makeNode(RenameStmt);
- newnode->relname = pstrdup(from->relname);
- newnode->inhOpt = from->inhOpt;
+ Node_Copy(from, newnode, relation);
if (from->column)
newnode->column = pstrdup(from->column);
if (from->newname)
{
RuleStmt *newnode = makeNode(RuleStmt);
+ Node_Copy(from, newnode, relation);
newnode->rulename = pstrdup(from->rulename);
Node_Copy(from, newnode, whereClause);
newnode->event = from->event;
- Node_Copy(from, newnode, object);
newnode->instead = from->instead;
Node_Copy(from, newnode, actions);
{
NotifyStmt *newnode = makeNode(NotifyStmt);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
return newnode;
}
{
ListenStmt *newnode = makeNode(ListenStmt);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
return newnode;
}
{
UnlistenStmt *newnode = makeNode(UnlistenStmt);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
return newnode;
}
{
ViewStmt *newnode = makeNode(ViewStmt);
- if (from->viewname)
- newnode->viewname = pstrdup(from->viewname);
+ Node_Copy(from, newnode, view);
Node_Copy(from, newnode, aliases);
Node_Copy(from, newnode, query);
newnode->analyze = from->analyze;
newnode->freeze = from->freeze;
newnode->verbose = from->verbose;
- if (from->vacrel)
- newnode->vacrel = pstrdup(from->vacrel);
+ Node_Copy(from, newnode, relation);
Node_Copy(from, newnode, va_cols);
return newnode;
{
CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
- if (from->seqname)
- newnode->seqname = pstrdup(from->seqname);
+ Node_Copy(from, newnode, sequence);
Node_Copy(from, newnode, options);
return newnode;
if (from->trigname)
newnode->trigname = pstrdup(from->trigname);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
if (from->funcname)
newnode->funcname = pstrdup(from->funcname);
Node_Copy(from, newnode, args);
newnode->isconstraint = from->isconstraint;
newnode->deferrable = from->deferrable;
newnode->initdeferred = from->initdeferred;
- if (from->constrrelname)
- newnode->constrrelname = pstrdup(from->constrrelname);
+ Node_Copy(from, newnode, constrrel);
return newnode;
}
if (from->trigname)
newnode->trigname = pstrdup(from->trigname);
- if (from->relname)
- newnode->relname = pstrdup(from->relname);
+ Node_Copy(from, newnode, relation);
return newnode;
}
{
LockStmt *newnode = makeNode(LockStmt);
- Node_Copy(from, newnode, rellist);
+ Node_Copy(from, newnode, relations);
newnode->mode = from->mode;
ReindexStmt *newnode = makeNode(ReindexStmt);
newnode->reindexType = from->reindexType;
+ Node_Copy(from, newnode, relation);
if (from->name)
newnode->name = pstrdup(from->name);
newnode->force = from->force;
return newnode;
}
+static CreateSchemaStmt *
+_copyCreateSchemaStmt(CreateSchemaStmt *from)
+{
+ CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
+
+ newnode->schemaname = pstrdup(from->schemaname);
+ if (from->authid)
+ newnode->authid = pstrdup(from->authid);
+ Node_Copy(from, newnode, schemaElts);
+
+ return newnode;
+}
+
/* ****************************************************************
* pg_list.h copy functions
case T_LoadStmt:
retval = _copyLoadStmt(from);
break;
+ case T_CreateDomainStmt:
+ retval = _copyCreateDomainStmt(from);
+ break;
case T_CreatedbStmt:
retval = _copyCreatedbStmt(from);
break;
case T_CheckPointStmt:
retval = (void *) makeNode(CheckPointStmt);
break;
+ case T_CreateSchemaStmt:
+ retval = _copyCreateSchemaStmt(from);
+ break;
case T_A_Expr:
retval = _copyAExpr(from);
break;
- case T_Attr:
- retval = _copyAttr(from);
+ case T_ColumnRef:
+ retval = _copyColumnRef(from);
+ break;
+ case T_ParamRef:
+ retval = _copyParamRef(from);
break;
case T_A_Const:
retval = _copyAConst(from);
break;
- case T_ParamNo:
- retval = _copyParamNo(from);
- break;
case T_Ident:
retval = _copyIdent(from);
break;
case T_A_Indices:
retval = _copyAIndices(from);
break;
+ case T_ExprFieldSelect:
+ retval = _copyExprFieldSelect(from);
+ break;
case T_ResTarget:
retval = _copyResTarget(from);
break;
case T_SortGroupBy:
retval = _copySortGroupBy(from);
break;
+ case T_Alias:
+ retval = _copyAlias(from);
+ break;
case T_RangeVar:
retval = _copyRangeVar(from);
break;
case T_FuncWithArgs:
retval = _copyFuncWithArgs(from);
break;
- case T_CreateDomainStmt:
- retval = _copyCreateDomainStmt(from);
- break;
default:
elog(ERROR, "copyObject: don't know how to copy node type %d",
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.119 2002/03/20 19:44:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.120 2002/03/21 16:00:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return false;
if (a->resultRelation != b->resultRelation)
return false;
- if (!equalstr(a->into, b->into))
+ if (!equal(a->into, b->into))
return false;
if (a->isPortal != b->isPortal)
return false;
if (a->isBinary != b->isBinary)
return false;
- if (a->isTemp != b->isTemp)
- return false;
if (a->hasAggs != b->hasAggs)
return false;
if (a->hasSubLinks != b->hasSubLinks)
static bool
_equalInsertStmt(InsertStmt *a, InsertStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (!equal(a->cols, b->cols))
return false;
static bool
_equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (!equal(a->whereClause, b->whereClause))
return false;
- if (a->inhOpt != b->inhOpt)
- return false;
return true;
}
static bool
_equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (!equal(a->targetList, b->targetList))
return false;
return false;
if (!equal(a->fromClause, b->fromClause))
return false;
- if (a->inhOpt != b->inhOpt)
- return false;
return true;
}
{
if (!equal(a->distinctClause, b->distinctClause))
return false;
- if (!equalstr(a->into, b->into))
- return false;
- if (a->istemp != b->istemp)
+ if (!equal(a->into, b->into))
return false;
if (!equal(a->intoColNames, b->intoColNames))
return false;
{
if (a->subtype != b->subtype)
return false;
- if (!equalstr(a->relname, b->relname))
- return false;
- if (a->inhOpt != b->inhOpt)
+ if (!equal(a->relation, b->relation))
return false;
if (!equalstr(a->name, b->name))
return false;
static bool
_equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (!equalstr(a->indexname, b->indexname))
return false;
{
if (a->binary != b->binary)
return false;
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (a->oids != b->oids)
return false;
static bool
_equalCreateStmt(CreateStmt *a, CreateStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (!equal(a->tableElts, b->tableElts))
return false;
- if (!equal(a->inhRelnames, b->inhRelnames))
+ if (!equal(a->inhRelations, b->inhRelations))
return false;
if (!equal(a->constraints, b->constraints))
return false;
- if (a->istemp != b->istemp)
- return false;
if (a->hasoids != b->hasoids)
return false;
static bool
_equalDropStmt(DropStmt *a, DropStmt *b)
{
- if (!equal(a->names, b->names))
+ if (!equal(a->objects, b->objects))
return false;
if (a->removeType != b->removeType)
return false;
static bool
_equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
{
- if (!equalstr(a->relName, b->relName))
+ if (!equal(a->relation, b->relation))
return false;
return true;
return false;
if (!equalstr(a->objname, b->objname))
return false;
+ if (!equalstr(a->objschema, b->objschema))
+ return false;
if (!equalstr(a->objproperty, b->objproperty))
return false;
if (!equal(a->objlist, b->objlist))
{
if (!equalstr(a->idxname, b->idxname))
return false;
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (!equalstr(a->accessMethod, b->accessMethod))
return false;
static bool
_equalRenameStmt(RenameStmt *a, RenameStmt *b)
{
- if (!equalstr(a->relname, b->relname))
- return false;
- if (a->inhOpt != b->inhOpt)
+ if (!equal(a->relation, b->relation))
return false;
if (!equalstr(a->column, b->column))
return false;
static bool
_equalRuleStmt(RuleStmt *a, RuleStmt *b)
{
+ if (!equal(a->relation, b->relation))
+ return false;
if (!equalstr(a->rulename, b->rulename))
return false;
if (!equal(a->whereClause, b->whereClause))
return false;
if (a->event != b->event)
return false;
- if (!equal(a->object, b->object))
- return false;
if (a->instead != b->instead)
return false;
if (!equal(a->actions, b->actions))
static bool
_equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
return true;
static bool
_equalListenStmt(ListenStmt *a, ListenStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
return true;
static bool
_equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
{
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
return true;
static bool
_equalViewStmt(ViewStmt *a, ViewStmt *b)
{
- if (!equalstr(a->viewname, b->viewname))
+ if (!equal(a->view, b->view))
return false;
if (!equal(a->aliases, b->aliases))
return false;
return false;
if (a->verbose != b->verbose)
return false;
- if (!equalstr(a->vacrel, b->vacrel))
+ if (!equal(a->relation, b->relation))
return false;
if (!equal(a->va_cols, b->va_cols))
return false;
static bool
_equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
{
- if (!equalstr(a->seqname, b->seqname))
+ if (!equal(a->sequence, b->sequence))
return false;
if (!equal(a->options, b->options))
return false;
{
if (!equalstr(a->trigname, b->trigname))
return false;
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
if (!equalstr(a->funcname, b->funcname))
return false;
return false;
if (a->initdeferred != b->initdeferred)
return false;
- if (!equalstr(a->constrrelname, b->constrrelname))
+ if (!equal(a->constrrel, b->constrrel))
return false;
return true;
{
if (!equalstr(a->trigname, b->trigname))
return false;
- if (!equalstr(a->relname, b->relname))
+ if (!equal(a->relation, b->relation))
return false;
return true;
static bool
_equalLockStmt(LockStmt *a, LockStmt *b)
{
- if (!equal(a->rellist, b->rellist))
+ if (!equal(a->relations, b->relations))
return false;
if (a->mode != b->mode)
return false;
{
if (a->reindexType != b->reindexType)
return false;
+ if (!equal(a->relation, b->relation))
+ return false;
if (!equalstr(a->name, b->name))
return false;
if (a->force != b->force)
return true;
}
+static bool
+_equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
+{
+ if (!equalstr(a->schemaname, b->schemaname))
+ return false;
+ if (!equalstr(a->authid, b->authid))
+ return false;
+ if (!equal(a->schemaElts, b->schemaElts))
+ return false;
+
+ return true;
+}
+
static bool
_equalAExpr(A_Expr *a, A_Expr *b)
{
}
static bool
-_equalAttr(Attr *a, Attr *b)
+_equalColumnRef(ColumnRef *a, ColumnRef *b)
{
- if (strcmp(a->relname, b->relname) != 0)
- return false;
- if (!equal(a->paramNo, b->paramNo))
- return false;
- if (!equal(a->attrs, b->attrs))
+ if (!equal(a->fields, b->fields))
return false;
if (!equal(a->indirection, b->indirection))
return false;
}
static bool
-_equalAConst(A_Const *a, A_Const *b)
+_equalParamRef(ParamRef *a, ParamRef *b)
{
- if (!equal(&a->val, &b->val))
+ if (a->number != b->number)
return false;
- if (!equal(a->typename, b->typename))
+ if (!equal(a->fields, b->fields))
+ return false;
+ if (!equal(a->indirection, b->indirection))
return false;
return true;
}
static bool
-_equalParamNo(ParamNo *a, ParamNo *b)
+_equalAConst(A_Const *a, A_Const *b)
{
- if (a->number != b->number)
+ if (!equal(&a->val, &b->val))
return false;
if (!equal(a->typename, b->typename))
return false;
- if (!equal(a->indirection, b->indirection))
- return false;
return true;
}
{
if (!equalstr(a->name, b->name))
return false;
- if (!equal(a->indirection, b->indirection))
- return false;
- if (a->isRel != b->isRel)
- return false;
return true;
}
return true;
}
+static bool
+_equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
+{
+ if (!equal(a->arg, b->arg))
+ return false;
+ if (!equal(a->fields, b->fields))
+ return false;
+ if (!equal(a->indirection, b->indirection))
+ return false;
+
+ return true;
+}
+
static bool
_equalResTarget(ResTarget *a, ResTarget *b)
{
return true;
}
+static bool
+_equalAlias(Alias *a, Alias *b)
+{
+ if (!equalstr(a->aliasname, b->aliasname))
+ return false;
+ if (!equal(a->colnames, b->colnames))
+ return false;
+
+ return true;
+}
+
static bool
_equalRangeVar(RangeVar *a, RangeVar *b)
{
+ if (!equalstr(a->catalogname, b->catalogname))
+ return false;
+ if (!equalstr(a->schemaname, b->schemaname))
+ return false;
if (!equalstr(a->relname, b->relname))
return false;
if (a->inhOpt != b->inhOpt)
return false;
- if (!equal(a->name, b->name))
+ if (a->istemp != b->istemp)
+ return false;
+ if (!equal(a->alias, b->alias))
return false;
return true;
{
if (!equal(a->subquery, b->subquery))
return false;
- if (!equal(a->name, b->name))
+ if (!equal(a->alias, b->alias))
return false;
return true;
{
if (!equalstr(a->constr_name, b->constr_name))
return false;
- if (!equalstr(a->pktable_name, b->pktable_name))
+ if (!equal(a->pktable, b->pktable))
return false;
if (!equal(a->fk_attrs, b->fk_attrs))
return false;
case T_CheckPointStmt:
retval = true;
break;
+ case T_CreateSchemaStmt:
+ retval = _equalCreateSchemaStmt(a, b);
+ break;
case T_A_Expr:
retval = _equalAExpr(a, b);
break;
- case T_Attr:
- retval = _equalAttr(a, b);
+ case T_ColumnRef:
+ retval = _equalColumnRef(a, b);
+ break;
+ case T_ParamRef:
+ retval = _equalParamRef(a, b);
break;
case T_A_Const:
retval = _equalAConst(a, b);
break;
- case T_ParamNo:
- retval = _equalParamNo(a, b);
- break;
case T_Ident:
retval = _equalIdent(a, b);
break;
case T_A_Indices:
retval = _equalAIndices(a, b);
break;
+ case T_ExprFieldSelect:
+ retval = _equalExprFieldSelect(a, b);
+ break;
case T_ResTarget:
retval = _equalResTarget(a, b);
break;
case T_SortGroupBy:
retval = _equalSortGroupBy(a, b);
break;
+ case T_Alias:
+ retval = _equalAlias(a, b);
+ break;
case T_RangeVar:
retval = _equalRangeVar(a, b);
break;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.27 2002/03/20 19:44:04 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.28 2002/03/21 16:00:40 tgl Exp $
*/
#include "postgres.h"
}
/*
- * makeAttr -
- * creates an Attr node
+ * makeAlias -
+ * creates an Alias node
+ *
+ * NOTE: the given name is copied, but the colnames list (if any) isn't.
*/
-Attr *
-makeAttr(char *relname, char *attname)
+Alias *
+makeAlias(const char *aliasname, List *colnames)
{
- Attr *a = makeNode(Attr);
+ Alias *a = makeNode(Alias);
- a->relname = pstrdup(relname);
- a->paramNo = NULL;
- if (attname != NULL)
- a->attrs = makeList1(makeString(pstrdup(attname)));
- a->indirection = NULL;
+ a->aliasname = pstrdup(aliasname);
+ a->colnames = colnames;
return a;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.16 2001/10/28 06:25:44 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.17 2002/03/21 16:00:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
bool
single_node(Node *node)
{
- if (IsA(node, Ident) ||IsA(node, Const) ||IsA(node, Var) ||IsA(node, Param))
+ if (IsA(node, Const) ||
+ IsA(node, Var) ||
+ IsA(node, Param))
return true;
else
return false;
* non_null -
* Returns t if the node is a non-null constant, e.g., if the node has a
* valid `constvalue' field.
- *
*/
bool
non_null(Expr *c)
{
- if (IsA(c, Const) &&!((Const *) c)->constisnull)
+ if (IsA(c, Const) &&
+ !((Const *) c)->constisnull)
return true;
else
return false;
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.149 2002/03/12 00:51:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.150 2002/03/21 16:00:40 tgl Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
static void
_outCreateStmt(StringInfo str, CreateStmt *node)
{
- appendStringInfo(str, " CREATE :relname ");
- _outToken(str, node->relname);
+ appendStringInfo(str, " CREATE :relation ");
+ _outNode(str, node->relation);
- appendStringInfo(str, " :columns ");
+ appendStringInfo(str, " :tableElts ");
_outNode(str, node->tableElts);
- appendStringInfo(str, " :inhRelnames ");
- _outNode(str, node->inhRelnames);
+ appendStringInfo(str, " :inhRelations ");
+ _outNode(str, node->inhRelations);
appendStringInfo(str, " :constraints ");
_outNode(str, node->constraints);
- appendStringInfo(str, " :istemp %s :hasoids %s ",
- booltostr(node->istemp),
+ appendStringInfo(str, " :hasoids %s ",
booltostr(node->hasoids));
}
{
appendStringInfo(str, " INDEX :idxname ");
_outToken(str, node->idxname);
- appendStringInfo(str, " :relname ");
- _outToken(str, node->relname);
+ appendStringInfo(str, " :relation ");
+ _outNode(str, node->relation);
appendStringInfo(str, " :accessMethod ");
_outToken(str, node->accessMethod);
appendStringInfo(str, " :indexParams ");
booltostr(node->primary));
}
+static void
+_outNotifyStmt(StringInfo str, NotifyStmt *node)
+{
+ appendStringInfo(str, "NOTIFY :relation ");
+ _outNode(str, node->relation);
+}
+
static void
_outSelectStmt(StringInfo str, SelectStmt *node)
{
static void
_outQuery(StringInfo str, Query *node)
{
+ appendStringInfo(str, " QUERY :command %d :utility ", node->commandType);
- appendStringInfo(str, " QUERY :command %d ", node->commandType);
-
+ /*
+ * Hack to work around missing outfuncs routines for a lot of the
+ * utility-statement node types. (The only one we actually *need*
+ * for rules support is NotifyStmt.) Someday we ought to support
+ * 'em all, but for the meantime do this to avoid getting lots of
+ * warnings when running with debug_print_parse on.
+ */
if (node->utilityStmt)
{
- /*
- * Hack to make up for lack of outfuncs for utility-stmt nodes
- */
switch (nodeTag(node->utilityStmt))
{
case T_CreateStmt:
- appendStringInfo(str, " :create ");
- _outToken(str, ((CreateStmt *) (node->utilityStmt))->relname);
- appendStringInfo(str, " ");
- _outNode(str, node->utilityStmt);
- break;
-
case T_IndexStmt:
- appendStringInfo(str, " :index ");
- _outToken(str, ((IndexStmt *) (node->utilityStmt))->idxname);
- appendStringInfo(str, " on ");
- _outToken(str, ((IndexStmt *) (node->utilityStmt))->relname);
- appendStringInfo(str, " ");
- _outNode(str, node->utilityStmt);
- break;
-
case T_NotifyStmt:
- appendStringInfo(str, " :notify ");
- _outToken(str, ((NotifyStmt *) (node->utilityStmt))->relname);
+ _outNode(str, node->utilityStmt);
break;
-
default:
- appendStringInfo(str, " :utility ? ");
+ appendStringInfo(str, "?");
+ break;
}
}
else
- appendStringInfo(str, " :utility <>");
+ appendStringInfo(str, "<>");
appendStringInfo(str, " :resultRelation %d :into ",
node->resultRelation);
- _outToken(str, node->into);
+ _outNode(str, node->into);
- appendStringInfo(str, " :isPortal %s :isBinary %s :isTemp %s"
+ appendStringInfo(str, " :isPortal %s :isBinary %s"
" :hasAggs %s :hasSubLinks %s :rtable ",
booltostr(node->isPortal),
booltostr(node->isBinary),
- booltostr(node->isTemp),
booltostr(node->hasAggs),
booltostr(node->hasSubLinks));
_outNode(str, node->rtable);
_outNode(str, node->expr);
}
+static void
+_outAlias(StringInfo str, Alias *node)
+{
+ appendStringInfo(str, " ALIAS :aliasname ");
+ _outToken(str, node->aliasname);
+ appendStringInfo(str, " :colnames ");
+ _outNode(str, node->colnames);
+}
+
static void
_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
{
}
static void
-_outIdent(StringInfo str, Ident *node)
+_outRangeVar(StringInfo str, RangeVar *node)
{
- appendStringInfo(str, " IDENT ");
- _outToken(str, node->name);
+ appendStringInfo(str, " RANGEVAR :relation ");
+ /*
+ * we deliberately ignore catalogname here, since it is presently not
+ * semantically meaningful
+ */
+ _outToken(str, node->schemaname);
+ appendStringInfo(str, " . ");
+ _outToken(str, node->relname);
+ appendStringInfo(str, " :inhopt %d :istemp %s",
+ (int) node->inhOpt,
+ booltostr(node->istemp));
+ appendStringInfo(str, " :alias ");
+ _outNode(str, node->alias);
}
static void
-_outAttr(StringInfo str, Attr *node)
+_outColumnRef(StringInfo str, ColumnRef *node)
{
- appendStringInfo(str, " ATTR :relname ");
- _outToken(str, node->relname);
- appendStringInfo(str, " :attrs ");
- _outNode(str, node->attrs);
+ appendStringInfo(str, " COLUMNREF :fields ");
+ _outNode(str, node->fields);
+ appendStringInfo(str, " :indirection ");
+ _outNode(str, node->indirection);
+}
+
+static void
+_outParamRef(StringInfo str, ParamRef *node)
+{
+ appendStringInfo(str, " PARAMREF :number %d :fields ", node->number);
+ _outNode(str, node->fields);
+ appendStringInfo(str, " :indirection ");
+ _outNode(str, node->indirection);
+}
+
+static void
+_outIdent(StringInfo str, Ident *node)
+{
+ appendStringInfo(str, " IDENT ");
+ _outToken(str, node->name);
}
static void
_outNode(str, node->typename);
}
+static void
+_outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
+{
+ appendStringInfo(str, " EXPRFIELDSELECT :arg ");
+ _outNode(str, node->arg);
+ appendStringInfo(str, " :fields ");
+ _outNode(str, node->fields);
+ appendStringInfo(str, " :indirection ");
+ _outNode(str, node->indirection);
+}
+
static void
_outConstraint(StringInfo str, Constraint *node)
{
{
appendStringInfo(str, " FKCONSTRAINT :constr_name ");
_outToken(str, node->constr_name);
- appendStringInfo(str, " :pktable_name ");
- _outToken(str, node->pktable_name);
+ appendStringInfo(str, " :pktable ");
+ _outNode(str, node->pktable);
appendStringInfo(str, " :fk_attrs ");
_outNode(str, node->fk_attrs);
appendStringInfo(str, " :pk_attrs ");
case T_IndexStmt:
_outIndexStmt(str, obj);
break;
+ case T_NotifyStmt:
+ _outNotifyStmt(str, obj);
+ break;
+ case T_SelectStmt:
+ _outSelectStmt(str, obj);
+ break;
case T_ColumnDef:
_outColumnDef(str, obj);
break;
case T_TargetEntry:
_outTargetEntry(str, obj);
break;
+ case T_Alias:
+ _outAlias(str, obj);
+ break;
case T_RangeTblEntry:
_outRangeTblEntry(str, obj);
break;
case T_A_Expr:
_outAExpr(str, obj);
break;
+ case T_RangeVar:
+ _outRangeVar(str, obj);
+ break;
+ case T_ColumnRef:
+ _outColumnRef(str, obj);
+ break;
+ case T_ParamRef:
+ _outParamRef(str, obj);
+ break;
case T_Ident:
_outIdent(str, obj);
break;
case T_A_Const:
_outAConst(str, obj);
break;
+ case T_ExprFieldSelect:
+ _outExprFieldSelect(str, obj);
+ break;
case T_Constraint:
_outConstraint(str, obj);
break;
case T_BooleanTest:
_outBooleanTest(str, obj);
break;
- case T_VariableSetStmt:
- break;
- case T_SelectStmt:
- _outSelectStmt(str, obj);
- break;
case T_FuncCall:
_outFuncCall(str, obj);
break;
- case T_Attr:
- _outAttr(str, obj);
- break;
default:
elog(WARNING, "_outNode: don't know how to print type %d ",
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.51 2001/12/20 02:39:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.52 2002/03/21 16:00:41 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
if (rte->relname)
printf("%d\t%s (%s)\t%u",
- i, rte->relname, rte->eref->relname, rte->relid);
+ i, rte->relname, rte->eref->aliasname, rte->relid);
else
printf("%d\t[subquery] (%s)\t",
- i, rte->eref->relname);
+ i, rte->eref->aliasname);
printf("\t%s\t%s\n",
(rte->inh ? "inh" : ""),
(rte->inFromCl ? "inFromCl" : ""));
Assert(var->varno > 0 &&
(int) var->varno <= length(rtable));
rte = rt_fetch(var->varno, rtable);
- relname = rte->eref->relname;
+ relname = rte->eref->aliasname;
attname = get_rte_attribute_name(rte, var->varattno);
}
break;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.116 2002/03/12 00:51:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.117 2002/03/21 16:00:42 tgl Exp $
*
* NOTES
* Most of the read functions for plan nodes are tested. (In fact, they
local_node = makeNode(Query);
- token = pg_strtok(&length); /* skip the :command */
- token = pg_strtok(&length); /* get the commandType */
+ token = pg_strtok(&length); /* skip :command */
+ token = pg_strtok(&length); /* get commandType */
local_node->commandType = atoi(token);
token = pg_strtok(&length); /* skip :utility */
- token = pg_strtok(&length);
- if (length == 0)
- local_node->utilityStmt = NULL;
- else
- {
- /*
- * Hack to make up for lack of readfuncs for utility-stmt nodes
- *
- * we can't get create or index here, can we?
- */
- NotifyStmt *n = makeNode(NotifyStmt);
-
- n->relname = debackslash(token, length);
- local_node->utilityStmt = (Node *) n;
- }
+ local_node->utilityStmt = nodeRead(true);
- token = pg_strtok(&length); /* skip the :resultRelation */
+ token = pg_strtok(&length); /* skip :resultRelation */
token = pg_strtok(&length); /* get the resultRelation */
local_node->resultRelation = atoi(token);
token = pg_strtok(&length); /* skip :into */
- token = pg_strtok(&length); /* get into */
- local_node->into = nullable_string(token, length);
+ local_node->into = nodeRead(true);
token = pg_strtok(&length); /* skip :isPortal */
token = pg_strtok(&length); /* get isPortal */
token = pg_strtok(&length); /* get isBinary */
local_node->isBinary = strtobool(token);
- token = pg_strtok(&length); /* skip :isTemp */
- token = pg_strtok(&length); /* get isTemp */
- local_node->isTemp = strtobool(token);
-
token = pg_strtok(&length); /* skip the :hasAggs */
token = pg_strtok(&length); /* get hasAggs */
local_node->hasAggs = strtobool(token);
return local_node;
}
+/* ----------------
+ * _readNotifyStmt
+ * ----------------
+ */
+static NotifyStmt *
+_readNotifyStmt(void)
+{
+ NotifyStmt *local_node;
+ char *token;
+ int length;
+
+ local_node = makeNode(NotifyStmt);
+
+ token = pg_strtok(&length); /* skip :relation */
+ local_node->relation = nodeRead(true);
+
+ return local_node;
+}
+
/* ----------------
* _readSortClause
* ----------------
return local_node;
}
-static Attr *
-_readAttr(void)
+static RangeVar *
+_readRangeVar(void)
{
- Attr *local_node;
+ RangeVar *local_node;
char *token;
int length;
- local_node = makeNode(Attr);
+ local_node = makeNode(RangeVar);
- token = pg_strtok(&length); /* eat :relname */
+ local_node->catalogname = NULL; /* not currently saved in output format */
+
+ token = pg_strtok(&length); /* eat :relation */
+ token = pg_strtok(&length); /* get schemaname */
+ local_node->schemaname = nullable_string(token, length);
+
+ token = pg_strtok(&length); /* eat "." */
token = pg_strtok(&length); /* get relname */
- local_node->relname = debackslash(token, length);
+ local_node->relname = nullable_string(token, length);
+
+ token = pg_strtok(&length); /* eat :inhopt */
+ token = pg_strtok(&length); /* get inhopt */
+ local_node->inhOpt = (InhOption) atoi(token);
+
+ token = pg_strtok(&length); /* eat :istemp */
+ token = pg_strtok(&length); /* get istemp */
+ local_node->istemp = strtobool(token);
+
+ token = pg_strtok(&length); /* eat :alias */
+ local_node->alias = nodeRead(true); /* now read it */
+
+ return local_node;
+}
+
+static ColumnRef *
+_readColumnRef(void)
+{
+ ColumnRef *local_node;
+ char *token;
+ int length;
+
+ local_node = makeNode(ColumnRef);
+
+ token = pg_strtok(&length); /* eat :fields */
+ local_node->fields = nodeRead(true); /* now read it */
+
+ token = pg_strtok(&length); /* eat :indirection */
+ local_node->indirection = nodeRead(true); /* now read it */
+
+ return local_node;
+}
+
+static ExprFieldSelect *
+_readExprFieldSelect(void)
+{
+ ExprFieldSelect *local_node;
+ char *token;
+ int length;
+
+ local_node = makeNode(ExprFieldSelect);
+
+ token = pg_strtok(&length); /* eat :arg */
+ local_node->arg = nodeRead(true); /* now read it */
+
+ token = pg_strtok(&length); /* eat :fields */
+ local_node->fields = nodeRead(true); /* now read it */
+
+ token = pg_strtok(&length); /* eat :indirection */
+ local_node->indirection = nodeRead(true); /* now read it */
+
+ return local_node;
+}
+
+static Alias *
+_readAlias(void)
+{
+ Alias *local_node;
+ char *token;
+ int length;
+
+ local_node = makeNode(Alias);
+
+ token = pg_strtok(&length); /* eat :aliasname */
+ token = pg_strtok(&length); /* get aliasname */
+ local_node->aliasname = debackslash(token, length);
- token = pg_strtok(&length); /* eat :attrs */
- local_node->attrs = nodeRead(true); /* now read it */
+ token = pg_strtok(&length); /* eat :colnames */
+ local_node->colnames = nodeRead(true); /* now read it */
return local_node;
}
return_value = _readArrayRef();
else if (length == 3 && strncmp(token, "VAR", length) == 0)
return_value = _readVar();
- else if (length == 4 && strncmp(token, "ATTR", length) == 0)
- return_value = _readAttr();
else if (length == 5 && strncmp(token, "CONST", length) == 0)
return_value = _readConst();
else if (length == 4 && strncmp(token, "FUNC", length) == 0)
return_value = _readParam();
else if (length == 11 && strncmp(token, "TARGETENTRY", length) == 0)
return_value = _readTargetEntry();
+ else if (length == 8 && strncmp(token, "RANGEVAR", length) == 0)
+ return_value = _readRangeVar();
+ else if (length == 9 && strncmp(token, "COLUMNREF", length) == 0)
+ return_value = _readColumnRef();
+ else if (length == 15 && strncmp(token, "EXPRFIELDSELECT", length) == 0)
+ return_value = _readExprFieldSelect();
+ else if (length == 5 && strncmp(token, "ALIAS", length) == 0)
+ return_value = _readAlias();
else if (length == 3 && strncmp(token, "RTE", length) == 0)
return_value = _readRangeTblEntry();
else if (length == 4 && strncmp(token, "PATH", length) == 0)
return_value = _readIter();
else if (length == 5 && strncmp(token, "QUERY", length) == 0)
return_value = _readQuery();
+ else if (length == 6 && strncmp(token, "NOTIFY", length) == 0)
+ return_value = _readNotifyStmt();
else if (length == 10 && strncmp(token, "SORTCLAUSE", length) == 0)
return_value = _readSortClause();
else if (length == 11 && strncmp(token, "GROUPCLAUSE", length) == 0)
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.94 2002/03/12 00:51:50 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.95 2002/03/21 16:00:44 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
rte = rt_fetch(var->varno, context->query->rtable);
attname = get_rte_attribute_name(rte, var->varattno);
elog(ERROR, "Sub-SELECT uses un-GROUPed attribute %s.%s from outer query",
- rte->eref->relname, attname);
+ rte->eref->aliasname, attname);
}
}
}
return false;
switch (nodeTag(node))
{
- case T_Ident:
case T_Const:
case T_Var:
case T_Param:
return NULL;
switch (nodeTag(node))
{
- case T_Ident:
case T_Const:
case T_Var:
case T_Param:
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.220 2002/03/12 00:51:52 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.221 2002/03/21 16:00:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#endif
+/* State shared by transformCreateSchemaStmt and its subroutines */
+typedef struct
+{
+ const char *stmtType; /* "CREATE TABLE" or "ALTER TABLE" */
+ char *schemaname; /* name of schema */
+ char *authid; /* owner of schema */
+ List *tables; /* CREATE TABLE items */
+ List *views; /* CREATE VIEW items */
+ List *grants; /* GRANT items */
+ List *fwconstraints; /* Forward referencing FOREIGN KEY constraints */
+ List *alters; /* Generated ALTER items (from the above) */
+ List *ixconstraints; /* index-creating constraints */
+ List *blist; /* "before list" of things to do before
+ * creating the schema */
+ List *alist; /* "after list" of things to do after
+ * creating the schema */
+} CreateSchemaStmtContext;
+
/* State shared by transformCreateStmt and its subroutines */
typedef struct
{
const char *stmtType; /* "CREATE TABLE" or "ALTER TABLE" */
- char *relname; /* name of relation */
- List *inhRelnames; /* names of relations to inherit from */
- bool istemp; /* is it to be a temp relation? */
+ RangeVar *relation; /* relation to create */
+ List *inhRelations; /* relations to inherit from */
bool hasoids; /* does relation have an OID column? */
Oid relOid; /* OID of table, if ALTER TABLE case */
List *columns; /* ColumnDef items */
qry->commandType = CMD_DELETE;
/* set up range table with just the result rel */
- qry->resultRelation = setTargetTable(pstate, stmt->relname,
- interpretInhOption(stmt->inhOpt),
+ qry->resultRelation = setTargetTable(pstate, stmt->relation->relname,
+ interpretInhOption(stmt->relation->inhOpt),
true);
qry->distinctClause = NIL;
* table is also mentioned in the SELECT part. Note that the target
* table is not added to the joinlist or namespace.
*/
- qry->resultRelation = setTargetTable(pstate, stmt->relname,
+ qry->resultRelation = setTargetTable(pstate, stmt->relation->relname,
false, false);
/*
*/
rte = addRangeTableEntryForSubquery(pstate,
selectQuery,
- makeAttr("*SELECT*", NULL),
+ makeAlias("*SELECT*", NIL),
true);
rtr = makeNode(RangeTblRef);
/* assume new rte is at end */
foreach(tl, qry->targetList)
{
TargetEntry *tle = (TargetEntry *) lfirst(tl);
- Ident *id;
+ ResTarget *col;
Assert(!tle->resdom->resjunk);
if (icolumns == NIL || attnos == NIL)
elog(ERROR, "INSERT has more expressions than target columns");
- id = (Ident *) lfirst(icolumns);
- updateTargetListEntry(pstate, tle, id->name, lfirsti(attnos),
- id->indirection);
+ col = (ResTarget *) lfirst(icolumns);
+ Assert(IsA(col, ResTarget));
+ updateTargetListEntry(pstate, tle, col->name, lfirsti(attnos),
+ col->indirection);
icolumns = lnext(icolumns);
attnos = lnext(attnos);
}
List *elements;
cxt.stmtType = "CREATE TABLE";
- cxt.relname = stmt->relname;
- cxt.inhRelnames = stmt->inhRelnames;
- cxt.istemp = stmt->istemp;
+ cxt.relation = stmt->relation;
+ cxt.inhRelations = stmt->inhRelations;
cxt.hasoids = stmt->hasoids;
cxt.relOid = InvalidOid;
cxt.columns = NIL;
* conflicting constraints the user wrote (like a different
* DEFAULT).
*/
- sname = makeObjectName(cxt->relname, column->colname, "seq");
+ sname = makeObjectName((cxt->relation)->relname, column->colname, "seq");
/*
* Create an expression tree representing the function call
* CREATE/ALTER TABLE.
*/
sequence = makeNode(CreateSeqStmt);
- sequence->seqname = pstrdup(sname);
- sequence->istemp = cxt->istemp;
+ sequence->sequence = copyObject(cxt->relation);
+ sequence->sequence->relname = pstrdup(sname);
sequence->options = NIL;
elog(NOTICE, "%s will create implicit sequence '%s' for SERIAL column '%s.%s'",
- cxt->stmtType, sequence->seqname, cxt->relname, column->colname);
+ cxt->stmtType, sequence->sequence->relname, (cxt->relation)->relname, column->colname);
cxt->blist = lappend(cxt->blist, sequence);
}
Ident *id = makeNode(Ident);
id->name = column->colname;
- id->indirection = NIL;
- id->isRel = false;
-
fkconstraint->fk_attrs = makeList1(id);
cxt->fkconstraints = lappend(cxt->fkconstraints, fkconstraint);
case CONSTR_NULL:
if (saw_nullable && column->is_not_null)
elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
- cxt->stmtType, cxt->relname, column->colname);
+ cxt->stmtType, (cxt->relation)->relname, column->colname);
column->is_not_null = FALSE;
saw_nullable = true;
break;
case CONSTR_NOTNULL:
if (saw_nullable && !column->is_not_null)
elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
- cxt->stmtType, cxt->relname, column->colname);
+ cxt->stmtType, (cxt->relation)->relname, column->colname);
column->is_not_null = TRUE;
saw_nullable = true;
break;
case CONSTR_DEFAULT:
if (column->raw_default != NULL)
elog(ERROR, "%s/DEFAULT multiple values specified for '%s.%s'",
- cxt->stmtType, cxt->relname, column->colname);
+ cxt->stmtType, (cxt->relation)->relname, column->colname);
column->raw_default = constraint->raw_expr;
Assert(constraint->cooked_expr == NULL);
break;
case CONSTR_PRIMARY:
if (constraint->name == NULL)
- constraint->name = makeObjectName(cxt->relname,
+ constraint->name = makeObjectName((cxt->relation)->relname,
NULL,
"pkey");
if (constraint->keys == NIL)
case CONSTR_UNIQUE:
if (constraint->name == NULL)
- constraint->name = makeObjectName(cxt->relname,
+ constraint->name = makeObjectName((cxt->relation)->relname,
column->colname,
"key");
if (constraint->keys == NIL)
case CONSTR_CHECK:
if (constraint->name == NULL)
- constraint->name = makeObjectName(cxt->relname,
+ constraint->name = makeObjectName((cxt->relation)->relname,
column->colname,
NULL);
cxt->ckconstraints = lappend(cxt->ckconstraints, constraint);
{
case CONSTR_PRIMARY:
if (constraint->name == NULL)
- constraint->name = makeObjectName(cxt->relname,
+ constraint->name = makeObjectName((cxt->relation)->relname,
NULL,
"pkey");
cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
/* In ALTER TABLE case, a primary index might already exist */
if (cxt->pkey != NULL ||
(OidIsValid(cxt->relOid) &&
- relationHasPrimaryKey(cxt->relname)))
+ relationHasPrimaryKey((cxt->relation)->relname)))
elog(ERROR, "%s / PRIMARY KEY multiple primary keys"
" for table '%s' are not allowed",
- cxt->stmtType, cxt->relname);
+ cxt->stmtType, (cxt->relation)->relname);
cxt->pkey = index;
}
if (constraint->name != NULL)
index->idxname = pstrdup(constraint->name);
else if (constraint->contype == CONSTR_PRIMARY)
- index->idxname = makeObjectName(cxt->relname, NULL, "pkey");
+ index->idxname = makeObjectName((cxt->relation)->relname, NULL, "pkey");
else
index->idxname = NULL; /* will set it later */
- index->relname = cxt->relname;
+ index->relation = cxt->relation;
index->accessMethod = DEFAULT_INDEX_TYPE;
index->indexParams = NIL;
index->whereClause = NULL;
*/
found = true;
}
- else if (cxt->inhRelnames)
+ else if (cxt->inhRelations)
{
/* try inherited tables */
List *inher;
- foreach(inher, cxt->inhRelnames)
+ foreach(inher, cxt->inhRelations)
{
- Value *inh = lfirst(inher);
+ RangeVar *inh = lfirst(inher);
Relation rel;
int count;
- Assert(IsA(inh, String));
- rel = heap_openr(strVal(inh), AccessShareLock);
+ Assert(IsA(inh, RangeVar));
+ rel = heap_openr(inh->relname, AccessShareLock);
if (rel->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "inherited table \"%s\" is not a relation",
strVal(inh));
if (index->idxname == NULL && index->indexParams != NIL)
{
iparam = lfirst(index->indexParams);
- index->idxname = CreateIndexName(cxt->relname, iparam->name,
+ index->idxname = CreateIndexName((cxt->relation)->relname, iparam->name,
"key", cxt->alist);
}
if (index->idxname == NULL) /* should not happen */
cxt->stmtType,
(strcmp(cxt->stmtType, "ALTER TABLE") == 0) ? "ADD " : "",
(index->primary ? "PRIMARY KEY" : "UNIQUE"),
- index->idxname, cxt->relname);
+ index->idxname, (cxt->relation)->relname);
}
}
*/
if (fkconstraint->pk_attrs == NIL)
{
- if (strcmp(fkconstraint->pktable_name, cxt->relname) != 0)
+ if (strcmp(fkconstraint->pktable->relname, (cxt->relation)->relname) != 0)
transformFkeyGetPrimaryKey(fkconstraint, pktypoid);
else if (cxt->pkey != NULL)
{
Ident *pkattr = (Ident *) makeNode(Ident);
pkattr->name = pstrdup(ielem->name);
- pkattr->indirection = NIL;
- pkattr->isRel = false;
fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs,
pkattr);
if (attnum >= INDEX_MAX_KEYS)
transformFkeyGetPrimaryKey(fkconstraint, pktypoid);
else
elog(ERROR, "PRIMARY KEY for referenced table \"%s\" not found",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
}
}
else
{
/* Validate the specified referenced key list */
- if (strcmp(fkconstraint->pktable_name, cxt->relname) != 0)
+ if (strcmp(fkconstraint->pktable->relname, (cxt->relation)->relname) != 0)
transformFkeyCheckAttrs(fkconstraint, pktypoid);
else
{
transformFkeyCheckAttrs(fkconstraint, pktypoid);
else
elog(ERROR, "UNIQUE constraint matching given keys for referenced table \"%s\" not found",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
}
}
}
*/
fk_trigger = (CreateTrigStmt *) makeNode(CreateTrigStmt);
fk_trigger->trigname = fkconstraint->constr_name;
- fk_trigger->relname = cxt->relname;
+ fk_trigger->relation = cxt->relation;
fk_trigger->funcname = "RI_FKey_check_ins";
fk_trigger->before = false;
fk_trigger->row = true;
fk_trigger->isconstraint = true;
fk_trigger->deferrable = fkconstraint->deferrable;
fk_trigger->initdeferred = fkconstraint->initdeferred;
- fk_trigger->constrrelname = fkconstraint->pktable_name;
+ fk_trigger->constrrel = fkconstraint->pktable;
fk_trigger->args = NIL;
fk_trigger->args = lappend(fk_trigger->args,
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
- makeString(cxt->relname));
+ makeString((cxt->relation)->relname));
fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->pktable_name));
+ makeString(fkconstraint->pktable->relname));
fk_trigger->args = lappend(fk_trigger->args,
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
if (length(fk_attr) != length(pk_attr))
elog(ERROR, "number of key attributes in referenced table must be equal to foreign key"
"\n\tIllegal FOREIGN KEY definition references \"%s\"",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
while (fk_attr != NIL)
{
*/
fk_trigger = (CreateTrigStmt *) makeNode(CreateTrigStmt);
fk_trigger->trigname = fkconstraint->constr_name;
- fk_trigger->relname = fkconstraint->pktable_name;
+ fk_trigger->relation = fkconstraint->pktable;
fk_trigger->before = false;
fk_trigger->row = true;
fk_trigger->actions[0] = 'd';
fk_trigger->isconstraint = true;
fk_trigger->deferrable = fkconstraint->deferrable;
fk_trigger->initdeferred = fkconstraint->initdeferred;
- fk_trigger->constrrelname = cxt->relname;
+ fk_trigger->constrrel = cxt->relation;
switch ((fkconstraint->actions & FKCONSTR_ON_DELETE_MASK)
>> FKCONSTR_ON_DELETE_SHIFT)
{
fk_trigger->args = lappend(fk_trigger->args,
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
- makeString(cxt->relname));
+ makeString((cxt->relation)->relname));
fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->pktable_name));
+ makeString(fkconstraint->pktable->relname));
fk_trigger->args = lappend(fk_trigger->args,
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
*/
fk_trigger = (CreateTrigStmt *) makeNode(CreateTrigStmt);
fk_trigger->trigname = fkconstraint->constr_name;
- fk_trigger->relname = fkconstraint->pktable_name;
+ fk_trigger->relation = fkconstraint->pktable;
fk_trigger->before = false;
fk_trigger->row = true;
fk_trigger->actions[0] = 'u';
fk_trigger->isconstraint = true;
fk_trigger->deferrable = fkconstraint->deferrable;
fk_trigger->initdeferred = fkconstraint->initdeferred;
- fk_trigger->constrrelname = cxt->relname;
+ fk_trigger->constrrel = cxt->relation;
switch ((fkconstraint->actions & FKCONSTR_ON_UPDATE_MASK)
>> FKCONSTR_ON_UPDATE_SHIFT)
{
fk_trigger->args = lappend(fk_trigger->args,
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
- makeString(cxt->relname));
+ makeString((cxt->relation)->relname));
fk_trigger->args = lappend(fk_trigger->args,
- makeString(fkconstraint->pktable_name));
+ makeString(fkconstraint->pktable->relname));
fk_trigger->args = lappend(fk_trigger->args,
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
* easily support predicates on indexes created implicitly by
* CREATE TABLE. Fortunately, that's not necessary.
*/
- rte = addRangeTableEntry(pstate, stmt->relname, NULL, false, true);
+ rte = addRangeTableEntry(pstate, stmt->relation->relname, NULL, false, true);
/* no to join list, yes to namespace */
addRTEtoQuery(pstate, rte, false, true);
* beforehand. We don't need to hold a refcount on the relcache
* entry, however.
*/
- heap_close(heap_openr(stmt->object->relname, AccessExclusiveLock),
+ heap_close(heap_openr(stmt->relation->relname, AccessExclusiveLock),
NoLock);
/*
* rule qualification.
*/
Assert(pstate->p_rtable == NIL);
- oldrte = addRangeTableEntry(pstate, stmt->object->relname,
- makeAttr("*OLD*", NULL),
+ oldrte = addRangeTableEntry(pstate, stmt->relation->relname,
+ makeAlias("*OLD*", NIL),
false, true);
- newrte = addRangeTableEntry(pstate, stmt->object->relname,
- makeAttr("*NEW*", NULL),
+ newrte = addRangeTableEntry(pstate, stmt->relation->relname,
+ makeAlias("*NEW*", NIL),
false, true);
/* Must override addRangeTableEntry's default access-check flags */
oldrte->checkForRead = false;
* or they won't be accessible at all. We decide later
* whether to put them in the joinlist.
*/
- oldrte = addRangeTableEntry(sub_pstate, stmt->object->relname,
- makeAttr("*OLD*", NULL),
+ oldrte = addRangeTableEntry(sub_pstate, stmt->relation->relname,
+ makeAlias("*OLD*", NIL),
false, false);
- newrte = addRangeTableEntry(sub_pstate, stmt->object->relname,
- makeAttr("*NEW*", NULL),
+ newrte = addRangeTableEntry(sub_pstate, stmt->relation->relname,
+ makeAlias("*NEW*", NIL),
false, false);
oldrte->checkForRead = false;
newrte->checkForRead = false;
if (!IsTransactionBlock())
elog(ERROR, "DECLARE CURSOR may only be used in begin/end transaction blocks");
- qry->into = stmt->portalname;
- qry->isTemp = stmt->istemp;
+ qry->into = makeNode(RangeVar);
+ qry->into->relname = stmt->portalname;
qry->isPortal = TRUE;
qry->isBinary = stmt->binary; /* internal portal */
}
{
/* SELECT */
qry->into = stmt->into;
- qry->isTemp = stmt->istemp;
qry->isPortal = FALSE;
qry->isBinary = FALSE;
}
int leftmostRTI;
Query *leftmostQuery;
SetOperationStmt *sostmt;
- char *into;
- bool istemp;
+ RangeVar *into;
List *intoColNames;
char *portalname;
bool binary;
Assert(leftmostSelect && IsA(leftmostSelect, SelectStmt) &&
leftmostSelect->larg == NULL);
into = leftmostSelect->into;
- istemp = leftmostSelect->istemp;
intoColNames = leftmostSelect->intoColNames;
portalname = stmt->portalname;
binary = stmt->binary;
/* clear them to prevent complaints in transformSetOperationTree() */
leftmostSelect->into = NULL;
- leftmostSelect->istemp = false;
leftmostSelect->intoColNames = NIL;
stmt->portalname = NULL;
stmt->binary = false;
if (!IsTransactionBlock())
elog(ERROR, "DECLARE CURSOR may only be used in begin/end transaction blocks");
- qry->into = portalname;
- qry->isTemp = istemp;
+ qry->into = makeNode(RangeVar);
+ qry->into->relname = portalname;
qry->isPortal = TRUE;
qry->isBinary = binary; /* internal portal */
}
{
/* SELECT */
qry->into = into;
- qry->isTemp = istemp;
qry->isPortal = FALSE;
qry->isBinary = FALSE;
}
sprintf(selectName, "*SELECT* %d", length(pstate->p_rtable) + 1);
rte = addRangeTableEntryForSubquery(pstate,
selectQuery,
- makeAttr(pstrdup(selectName),
- NULL),
+ makeAlias(selectName, NIL),
false);
/*
qry->commandType = CMD_UPDATE;
pstate->p_is_update = true;
- qry->resultRelation = setTargetTable(pstate, stmt->relname,
- interpretInhOption(stmt->inhOpt),
+ qry->resultRelation = setTargetTable(pstate, stmt->relation->relname,
+ interpretInhOption(stmt->relation->inhOpt),
true);
/*
{
case 'A':
cxt.stmtType = "ALTER TABLE";
- cxt.relname = stmt->relname;
- cxt.inhRelnames = NIL;
- cxt.istemp = is_temp_rel_name(stmt->relname);
+ cxt.relation = stmt->relation;
+ cxt.inhRelations = NIL;
+ cxt.relation->istemp = is_temp_rel_name(stmt->relation->relname);
cxt.relOid = GetSysCacheOid(RELNAME,
- PointerGetDatum(stmt->relname),
+ PointerGetDatum((stmt->relation)->relname),
0, 0, 0);
cxt.hasoids = SearchSysCacheExists(ATTNUM,
ObjectIdGetDatum(cxt.relOid),
case 'C':
cxt.stmtType = "ALTER TABLE";
- cxt.relname = stmt->relname;
- cxt.inhRelnames = NIL;
- cxt.istemp = is_temp_rel_name(stmt->relname);
+ cxt.relation = stmt->relation;
+ cxt.inhRelations = NIL;
+ cxt.relation->istemp = is_temp_rel_name(stmt->relation->relname);
cxt.relOid = GetSysCacheOid(RELNAME,
- PointerGetDatum(stmt->relname),
+ PointerGetDatum((stmt->relation)->relname),
0, 0, 0);
cxt.hasoids = SearchSysCacheExists(ATTNUM,
ObjectIdGetDatum(cxt.relOid),
static void
transformTypeRef(ParseState *pstate, TypeName *tn)
{
- Attr *att;
+ ColumnRef *cref;
Node *n;
Var *v;
char *tyn;
if (tn->attrname == NULL)
return;
- att = makeAttr(tn->name, tn->attrname);
- n = transformExpr(pstate, (Node *) att, EXPR_COLUMN_FIRST);
+ /* XXX this needs work; can't type name be qualified? */
+ cref = makeNode(ColumnRef);
+ cref->fields = makeList2(makeString(tn->name), makeString(tn->attrname));
+ cref->indirection = NIL;
+ n = transformExpr(pstate, (Node *) cref);
if (!IsA(n, Var))
elog(ERROR, "unsupported expression in %%TYPE");
v = (Var *) n;
RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
++i;
- if (strcmp(rte->eref->relname, relname) == 0)
+ if (strcmp(rte->eref->aliasname, relname) == 0)
{
if (rte->subquery)
{
/*
* Open the referenced table
*/
- pkrel = heap_openr(fkconstraint->pktable_name, AccessShareLock);
+ pkrel = heap_openr(fkconstraint->pktable->relname, AccessShareLock);
if (pkrel->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "Referenced relation \"%s\" is not a table",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
/*
* Get the list of index OIDs for the table from the relcache, and
}
if (!found)
elog(ERROR, "UNIQUE constraint matching given keys for referenced table \"%s\" not found",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
freeList(indexoidlist);
heap_close(pkrel, AccessShareLock);
/*
* Open the referenced table
*/
- pkrel = heap_openr(fkconstraint->pktable_name, AccessShareLock);
+ pkrel = heap_openr(fkconstraint->pktable->relname, AccessShareLock);
if (pkrel->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "Referenced relation \"%s\" is not a table",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
/*
* Get the list of index OIDs for the table from the relcache, and
*/
if (indexStruct == NULL)
elog(ERROR, "PRIMARY KEY for referenced table \"%s\" not found",
- fkconstraint->pktable_name);
+ fkconstraint->pktable->relname);
/*
* Now build the list of PK attributes from the indkey definition
Ident *pkattr = makeNode(Ident);
pkattr->name = pstrdup(NameStr(*attnumAttName(pkrel, pkattno)));
- pkattr->indirection = NIL;
- pkattr->isRel = false;
pktypoid[attnum++] = attnumTypeId(pkrel, pkattno);
fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs, pkattr);
if (sysatt)
return sysatt->atttypid;
/* Look for column among inherited columns (if CREATE TABLE case) */
- foreach(inher, cxt->inhRelnames)
+ foreach(inher, cxt->inhRelations)
{
- Value *inh = lfirst(inher);
+ RangeVar *inh = lfirst(inher);
Relation rel;
int count;
- Assert(IsA(inh, String));
- rel = heap_openr(strVal(inh), AccessShareLock);
+ Assert(IsA(inh, RangeVar));
+ rel = heap_openr(inh->relname, AccessShareLock);
if (rel->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "inherited table \"%s\" is not a relation",
strVal(inh));
ReleaseSysCache(ctype);
}
+
+/*
+ * analyzeCreateSchemaStmt -
+ * analyzes the "create schema" statement
+ *
+ * Split the schema element list into individual commands and place
+ * them in the result list in an order such that there are no
+ * forward references (e.g. GRANT to a table created later in the list).
+ *
+ * SQL92 also allows constraints to make forward references, so thumb through
+ * the table columns and move forward references to a posterior alter-table
+ * command.
+ *
+ * The result is a list of parse nodes that still need to be analyzed ---
+ * but we can't analyze the later commands until we've executed the earlier
+ * ones, because of possible inter-object references.
+ *
+ * Note: Called from commands/command.c
+ */
+List *
+analyzeCreateSchemaStmt(CreateSchemaStmt *stmt)
+{
+ CreateSchemaStmtContext cxt;
+ List *result;
+ List *elements;
+
+ cxt.stmtType = "CREATE SCHEMA";
+ cxt.schemaname = stmt->schemaname;
+ cxt.authid = stmt->authid;
+ cxt.tables = NIL;
+ cxt.views = NIL;
+ cxt.grants = NIL;
+ cxt.fwconstraints = NIL;
+ cxt.alters = NIL;
+ cxt.blist = NIL;
+ cxt.alist = NIL;
+
+ /*
+ * Run through each schema element in the schema element list.
+ * Separate statements by type, and do preliminary analysis.
+ */
+ foreach(elements, stmt->schemaElts)
+ {
+ Node *element = lfirst(elements);
+
+ switch (nodeTag(element))
+ {
+ case T_CreateStmt:
+ {
+ CreateStmt *elp = (CreateStmt *) element;
+
+ if (elp->relation->schemaname == NULL)
+ elp->relation->schemaname = cxt.schemaname;
+ else if (strcmp(cxt.schemaname, elp->relation->schemaname))
+ elog(ERROR, "New table refers to a schema (%s)"
+ " different from the one being created (%s)",
+ elp->relation->schemaname, cxt.schemaname);
+
+ /*
+ * XXX todo: deal with constraints
+ */
+
+ cxt.tables = lappend(cxt.tables, element);
+ }
+ break;
+
+ case T_ViewStmt:
+ {
+ ViewStmt *elp = (ViewStmt *) element;
+
+ if (elp->view->schemaname == NULL)
+ elp->view->schemaname = cxt.schemaname;
+ else if (strcmp(cxt.schemaname, elp->view->schemaname))
+ elog(ERROR, "New view refers to a schema (%s)"
+ " different from the one being created (%s)",
+ elp->view->schemaname, cxt.schemaname);
+
+ /*
+ * XXX todo: deal with references between views
+ */
+
+ cxt.views = lappend(cxt.views, element);
+ }
+ break;
+
+ case T_GrantStmt:
+ cxt.grants = lappend(cxt.grants, element);
+ break;
+
+ default:
+ elog(ERROR, "parser: unsupported schema node (internal error)");
+ }
+ }
+
+ result = NIL;
+ result = nconc(result, cxt.tables);
+ result = nconc(result, cxt.views);
+ result = nconc(result, cxt.grants);
+
+ return result;
+}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.294 2002/03/20 19:44:21 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.295 2002/03/21 16:00:50 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
%}
+
%union
{
int ival;
List *list;
Node *node;
Value *value;
-
- Attr *attr;
- Ident *ident;
+ ColumnRef *columnref;
TypeName *typnam;
DefElem *defelt;
SortGroupBy *sortgroupby;
JoinExpr *jexpr;
IndexElem *ielem;
+ Alias *alias;
RangeVar *range;
A_Indices *aind;
ResTarget *target;
- ParamNo *paramno;
PrivTarget *privtarget;
VersionStmt *vstmt;
InsertStmt *istmt;
}
-%type stmt,
+%type stmt, schema_stmt,
AlterDatabaseSetStmt, AlterGroupStmt, AlterSchemaStmt, AlterTableStmt,
AlterUserStmt, AlterUserSetStmt, AnalyzeStmt,
ClosePortalStmt, ClusterStmt, CommentStmt, ConstraintsSetStmt,
%type OptUserList
%type OptUserElem
+%type OptSchemaName
+%type OptSchemaEltList
+
%type TriggerActionTime, TriggerForSpec, opt_trusted, opt_procedural
%type opt_lancompiler
-%type OptConstrFromTable
-
%type TriggerEvents
%type TriggerFuncArg
database_name, access_method_clause, access_method, attr_name,
class, index_name, name, func_name, file_name
+%type qualified_name, OptConstrFromTable
+
%type opt_id,
all_Op, MathOp, opt_name,
OptUseOp, opt_class, SpecialRuleRelation
%type TriggerOneEvent
%type stmtblock, stmtmulti,
- into_clause, OptTempTableName, relation_name_list,
OptTableElementList, OptInherit, definition, opt_distinct,
opt_with, func_args, func_args_list, func_as,
oper_argtypes, RuleActionList, RuleActionMulti,
opt_column_list, columnList, opt_name_list,
sort_clause, sortby_list, index_params, index_list, name_list,
- from_clause, from_list, opt_array_bounds,
- expr_list, attrs, target_list, update_target_list,
+ from_clause, from_list, opt_array_bounds, qualified_name_list,
+ expr_list, attrs, opt_attrs, target_list, update_target_list,
+ insert_column_list,
def_list, opt_indirection, group_clause, TriggerFuncArgs,
select_limit, opt_select_limit
+%type into_clause, OptTempTableName
+
%type func_arg, func_return, func_type, aggr_argtype
%type opt_arg, TriggerForOpt, TriggerForType, OptTemp, OptWithOids
%type OptTableElement, ConstraintElem
%type columnDef
%type def_elem
-%type def_arg, columnElem, where_clause,
+%type def_arg, columnElem, where_clause, insert_column_item,
a_expr, b_expr, c_expr, AexprConst,
in_expr, having_clause
%type row_descriptor, row_list, in_expr_nodes
%type OptCreateAs, CreateAsList
%type CreateAsElement
%type NumericOnly, FloatOnly, IntegerOnly
-%type
event_object, attr, alias_clause
+%type columnref
%type sortby
%type index_elem, func_index
%type table_ref
%type joined_table
%type relation_expr
%type target_el, update_target_el
%type Typename, SimpleTypename, ConstTypename
GenericType, Numeric, Character, ConstDatetime, ConstInterval, Bit
%type opt_as
+
/*
* If you make any token changes, remember to:
* - use "yacc -d" and update parse.h
*
*****************************************************************************/
-CreateSchemaStmt: CREATE SCHEMA UserId
+CreateSchemaStmt: CREATE SCHEMA OptSchemaName AUTHORIZATION UserId OptSchemaEltList
{
- /* for now, just make this the same as CREATE DATABASE */
- CreatedbStmt *n = makeNode(CreatedbStmt);
- n->dbname = $3;
- n->dbowner = NULL;
- n->dbpath = NULL;
- n->dbtemplate = NULL;
- n->encoding = -1;
+ CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
+ /* One can omit the schema name or the authorization id... */
+ if ($3 != NULL)
+ n->schemaname = $3;
+ else
+ n->schemaname = $5;
+ n->authid = $5;
+ n->schemaElts = $6;
+ $$ = (Node *)n;
+ }
+ | CREATE SCHEMA ColId OptSchemaEltList
+ {
+ CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
+ /* ...but not both */
+ n->schemaname = $3;
+ n->authid = NULL;
+ n->schemaElts = $4;
$$ = (Node *)n;
}
;
-AlterSchemaStmt: ALTER SCHEMA UserId
+AlterSchemaStmt: ALTER SCHEMA ColId
{
elog(ERROR, "ALTER SCHEMA not yet supported");
}
;
-DropSchemaStmt: DROP SCHEMA UserId
+DropSchemaStmt: DROP SCHEMA ColId
{
- DropdbStmt *n = makeNode(DropdbStmt);
- n->dbname = $3;
- $$ = (Node *)n;
+ elog(ERROR, "DROP SCHEMA not yet supported");
}
;
+OptSchemaName: ColId { $$ = $1; }
+ | /* EMPTY */ { $$ = NULL; }
+ ;
+
+OptSchemaEltList: OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
+ | /* EMPTY */ { $$ = NIL; }
+ ;
-
+/*
+ * schema_stmt are the ones that can show up inside a CREATE SCHEMA
+ * statement (in addition to by themselves).
+ */
+schema_stmt: CreateStmt
+ | GrantStmt
+ | ViewStmt
+ ;
/*****************************************************************************
*
ColId_or_Sconst: ColId { $$ = $1; }
| SCONST { $$ = $1; }
+ ;
VariableShowStmt: SHOW ColId
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'A';
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->def = $6;
$$ = (Node *)n;
}
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'T';
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->name = $6;
n->def = $7;
$$ = (Node *)n;
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'S';
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->name = $6;
n->def = (Node *) makeInteger($9);
$$ = (Node *)n;
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'M';
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->name = $6;
n->def = (Node *) makeString($9);
$$ = (Node *)n;
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'D';
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->name = $6;
n->behavior = $7;
$$ = (Node *)n;
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'C';
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->def = $5;
$$ = (Node *)n;
}
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'X';
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->name = $6;
n->behavior = $7;
$$ = (Node *)n;
}
/* ALTER TABLE CREATE TOAST TABLE */
- | ALTER TABLE relation_name CREATE TOAST TABLE
+ | ALTER TABLE qualified_name CREATE TOAST TABLE
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'E';
- n->relname = $3;
- n->inhOpt = INH_NO;
+ $3->inhOpt = INH_NO;
+ n->relation = $3;
$$ = (Node *)n;
}
/* ALTER TABLE OWNER TO UserId */
- | ALTER TABLE relation_name OWNER TO UserId
+ | ALTER TABLE qualified_name OWNER TO UserId
{
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'U';
- n->relname = $3;
- n->inhOpt = INH_NO;
+ $3->inhOpt = INH_NO;
+ n->relation = $3;
n->name = $6;
$$ = (Node *)n;
}
opt_drop_behavior: CASCADE { $$ = CASCADE; }
| RESTRICT { $$ = RESTRICT; }
| /* EMPTY */ { $$ = RESTRICT; /* default */ }
- ;
+ ;
+
/*****************************************************************************
*
*****************************************************************************/
-CopyStmt: COPY opt_binary relation_name opt_with_copy copy_dirn copy_file_name copy_delimiter copy_null
+CopyStmt: COPY opt_binary qualified_name opt_with_copy copy_dirn copy_file_name copy_delimiter copy_null
{
CopyStmt *n = makeNode(CopyStmt);
n->binary = $2;
- n->relname = $3;
+ n->relation = $3;
n->oids = $4;
n->direction = $5;
n->filename = $6;
| /*EMPTY*/ { $$ = TRUE; }
;
-copy_null: WITH NULL_P AS Sconst { $$ = $4; }
- | /*EMPTY*/ { $$ = "\\N"; }
+copy_null: WITH NULL_P AS Sconst { $$ = $4; }
+ | /*EMPTY*/ { $$ = "\\N"; }
+ ;
/*****************************************************************************
*
*
*****************************************************************************/
-CreateStmt: CREATE OptTemp TABLE relation_name '(' OptTableElementList ')' OptInherit OptWithOids
+CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')' OptInherit OptWithOids
{
CreateStmt *n = makeNode(CreateStmt);
- n->relname = $4;
+ $4->istemp = $2;
+ n->relation = $4;
n->tableElts = $6;
- n->inhRelnames = $8;
+ n->inhRelations = $8;
n->constraints = NIL;
- n->istemp = $2;
n->hasoids = $9;
$$ = (Node *)n;
}
n->name = NULL;
if (exprIsNullConstant($2))
{
- /*
- * DEFAULT NULL should be reported as empty expr
- * Required for NOT NULL Domain overrides
- */
+ /* DEFAULT NULL should be reported as empty expr */
n->raw_expr = NULL;
}
else
n->keys = NULL;
$$ = (Node *)n;
}
- | REFERENCES ColId opt_column_list key_match key_actions
+ | REFERENCES qualified_name opt_column_list key_match key_actions
{
FkConstraint *n = makeNode(FkConstraint);
n->constr_name = NULL;
- n->pktable_name = $2;
+ n->pktable = $2;
n->fk_attrs = NIL;
n->pk_attrs = $3;
n->match_type = $4;
n->keys = $4;
$$ = (Node *)n;
}
- | FOREIGN KEY '(' columnList ')' REFERENCES ColId opt_column_list
+ | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name opt_column_list
key_match key_actions ConstraintAttributeSpec
{
FkConstraint *n = makeNode(FkConstraint);
n->constr_name = NULL;
- n->pktable_name = $7;
+ n->pktable = $7;
n->fk_attrs = $4;
n->pk_attrs = $8;
n->match_type = $9;
}
;
+opt_column_list: '(' columnList ')' { $$ = $2; }
+ | /*EMPTY*/ { $$ = NIL; }
+ ;
+
+columnList: columnList ',' columnElem
+ { $$ = lappend($1, $3); }
+ | columnElem
+ { $$ = makeList1($1); }
+ ;
+
+columnElem: ColId
+ {
+ Ident *id = makeNode(Ident);
+ id->name = $1;
+ $$ = (Node *)id;
+ }
+ ;
+
key_match: MATCH FULL
{
$$ = "FULL";
| SET DEFAULT { $$ = FKCONSTR_ON_KEY_SETDEFAULT; }
;
-OptInherit: INHERITS '(' relation_name_list ')' { $$ = $3; }
+OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
| /*EMPTY*/ { $$ = NIL; }
;
* SELECT ... INTO.
*/
-CreateAsStmt: CREATE OptTemp TABLE relation_name OptCreateAs AS SelectStmt
+CreateAsStmt: CREATE OptTemp TABLE qualified_name OptCreateAs AS SelectStmt
{
/*
* When the SelectStmt is a set-operation tree, we must
SelectStmt *n = findLeftmostSelect((SelectStmt *) $7);
if (n->into != NULL)
elog(ERROR,"CREATE TABLE AS may not specify INTO");
- n->istemp = $2;
+ $4->istemp = $2;
n->into = $4;
n->intoColNames = $5;
$$ = $7;
*
*****************************************************************************/
-CreateSeqStmt: CREATE OptTemp SEQUENCE relation_name OptSeqList
+CreateSeqStmt: CREATE OptTemp SEQUENCE qualified_name OptSeqList
{
CreateSeqStmt *n = makeNode(CreateSeqStmt);
- n->istemp = $2;
- n->seqname = $4;
+ $4->istemp = $2;
+ n->sequence = $4;
n->options = $5;
$$ = (Node *)n;
}
NumericOnly: FloatOnly { $$ = $1; }
| IntegerOnly { $$ = $1; }
+ ;
FloatOnly: FCONST
{
opt_lancompiler: LANCOMPILER Sconst { $$ = $2; }
| /*EMPTY*/ { $$ = ""; }
+ ;
DropPLangStmt: DROP opt_procedural LANGUAGE ColId_or_Sconst
{
*****************************************************************************/
CreateTrigStmt: CREATE TRIGGER name TriggerActionTime TriggerEvents ON
- relation_name TriggerForSpec EXECUTE PROCEDURE
+ qualified_name TriggerForSpec EXECUTE PROCEDURE
name '(' TriggerFuncArgs ')'
{
CreateTrigStmt *n = makeNode(CreateTrigStmt);
n->trigname = $3;
- n->relname = $7;
+ n->relation = $7;
n->funcname = $11;
n->args = $13;
n->before = $4;
n->isconstraint = FALSE;
n->deferrable = FALSE;
n->initdeferred = FALSE;
- n->constrrelname = NULL;
+ n->constrrel = NULL;
$$ = (Node *)n;
}
| CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
- relation_name OptConstrFromTable
+ qualified_name OptConstrFromTable
ConstraintAttributeSpec
FOR EACH ROW EXECUTE PROCEDURE name '(' TriggerFuncArgs ')'
{
CreateTrigStmt *n = makeNode(CreateTrigStmt);
n->trigname = $4;
- n->relname = $8;
+ n->relation = $8;
n->funcname = $16;
n->args = $18;
n->before = FALSE;
n->deferrable = ($10 & 1) != 0;
n->initdeferred = ($10 & 2) != 0;
- n->constrrelname = $9;
+ n->constrrel = $9;
$$ = (Node *)n;
}
;
OptConstrFromTable: /* Empty */
{
- $$ = "";
+ $$ = NULL;
}
- | FROM relation_name
+ | FROM qualified_name
{
$$ = $2;
}
;
-DropTrigStmt: DROP TRIGGER name ON relation_name
+DropTrigStmt: DROP TRIGGER name ON qualified_name
{
DropTrigStmt *n = makeNode(DropTrigStmt);
n->trigname = $3;
- n->relname = $5;
+ n->relation = $5;
$$ = (Node *) n;
}
;
*
*****************************************************************************/
-DropStmt: DROP drop_type name_list opt_drop_behavior
+/* DropStmt needs to use qualified_name_list as many of the objects
+ * are relations or other schema objects (names can be schema-qualified) */
+
+DropStmt: DROP drop_type qualified_name_list opt_drop_behavior
{
DropStmt *n = makeNode(DropStmt);
n->removeType = $2;
- n->names = $3;
+ n->objects = $3;
n->behavior = $4;
$$ = (Node *)n;
}
*
*****************************************************************************/
-TruncateStmt: TRUNCATE opt_table relation_name
+TruncateStmt: TRUNCATE opt_table qualified_name
{
TruncateStmt *n = makeNode(TruncateStmt);
- n->relName = $3;
+ n->relation = $3;
$$ = (Node *)n;
}
;
n->comment = $6;
$$ = (Node *) n;
}
- | COMMENT ON COLUMN relation_name '.' attr_name IS comment_text
+ | COMMENT ON COLUMN ColId '.' attr_name IS comment_text
{
+ /*
+ * We can't use qualified_name here as the '.' causes a shift/red;
+ * with ColId we do not test for NEW and OLD as table names, but it is OK
+ * as they would fail anyway as COMMENT cannot appear in a RULE.
+ * ColumnRef is also innapropriate as we don't take subscripts
+ * or '*' and have a very precise number of elements (2 or 3)
+ * so we do it from scratch.
+ */
CommentStmt *n = makeNode(CommentStmt);
n->objtype = COLUMN;
+ n->objschema = NULL;
n->objname = $4;
n->objproperty = $6;
n->objlist = NULL;
n->comment = $8;
$$ = (Node *) n;
}
+ | COMMENT ON COLUMN ColId '.' ColId '.' attr_name IS comment_text
+ {
+ CommentStmt *n = makeNode(CommentStmt);
+ n->objtype = COLUMN;
+ n->objschema = $4;
+ n->objname = $6;
+ n->objproperty = $8;
+ n->objlist = NULL;
+ n->comment = $10;
+ $$ = (Node *) n;
+ }
| COMMENT ON AGGREGATE name '(' aggr_argtype ')' IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = AGGREGATE;
+ n->objschema = NULL;
n->objname = $4;
n->objproperty = NULL;
n->objlist = makeList1($6);
/* Obsolete syntax, but must support for awhile */
CommentStmt *n = makeNode(CommentStmt);
n->objtype = AGGREGATE;
+ n->objschema = NULL;
n->objname = $4;
n->objproperty = NULL;
n->objlist = makeList1($5);
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = FUNCTION;
+ n->objschema = NULL;
n->objname = $4;
n->objproperty = NULL;
n->objlist = $5;
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = OPERATOR;
+ n->objschema = NULL;
n->objname = $4;
n->objproperty = NULL;
n->objlist = $6;
n->comment = $9;
$$ = (Node *) n;
}
- | COMMENT ON TRIGGER name ON relation_name IS comment_text
+ | COMMENT ON TRIGGER name ON qualified_name IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = TRIGGER;
+ /* NOTE: schemaname here refers to the table in objproperty */
+ n->objschema = $6->schemaname;
n->objname = $4;
- n->objproperty = $6;
+ n->objproperty = $6->relname;
n->objlist = NULL;
n->comment = $8;
$$ = (Node *) n;
/* Don't bother trying to fold the first two rules into one using
opt_table. You're going to get conflicts. */
-privilege_target: relation_name_list
+privilege_target: qualified_name_list
{
PrivTarget *n = makeNode(PrivTarget);
n->objtype = TABLE;
n->objs = $1;
$$ = n;
}
- | TABLE relation_name_list
+ | TABLE qualified_name_list
{
PrivTarget *n = makeNode(PrivTarget);
n->objtype = TABLE;
*
*****************************************************************************/
-IndexStmt: CREATE index_opt_unique INDEX index_name ON relation_name
+IndexStmt: CREATE index_opt_unique INDEX index_name ON qualified_name
access_method_clause '(' index_params ')' where_clause
{
IndexStmt *n = makeNode(IndexStmt);
n->unique = $2;
n->idxname = $4;
- n->relname = $6;
+ n->relation = $6;
n->accessMethod = $7;
n->indexParams = $9;
n->whereClause = $11;
*
*****************************************************************************/
-ReindexStmt: REINDEX reindex_type name opt_force
+ReindexStmt: REINDEX reindex_type qualified_name opt_force
{
ReindexStmt *n = makeNode(ReindexStmt);
n->reindexType = $2;
+ n->relation = $3;
+ n->name = NULL;
+ n->force = $4;
+ $$ = (Node *)n;
+ }
+ | REINDEX DATABASE name opt_force
+ {
+ ReindexStmt *n = makeNode(ReindexStmt);
+ n->reindexType = DATABASE;
n->name = $3;
+ n->relation = NULL;
n->force = $4;
$$ = (Node *)n;
}
reindex_type: INDEX { $$ = INDEX; }
| TABLE { $$ = TABLE; }
- | DATABASE { $$ = DATABASE; }
;
+
opt_force: FORCE { $$ = TRUE; }
| /* EMPTY */ { $$ = FALSE; }
;
RenameStmt: ALTER TABLE relation_expr RENAME opt_column opt_name TO name
{
RenameStmt *n = makeNode(RenameStmt);
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->column = $6;
n->newname = $8;
$$ = (Node *)n;
/*****************************************************************************
*
- * QUERY: Define Rewrite Rule , Define Tuple Rule
- *
- * only rewrite rule is supported -- ay 9/94
+ * QUERY: Define Rewrite Rule
*
*****************************************************************************/
RuleStmt: CREATE RULE name AS
{ QueryIsRule=TRUE; }
- ON event TO event_object where_clause
+ ON event TO qualified_name where_clause
DO opt_instead RuleActionList
{
RuleStmt *n = makeNode(RuleStmt);
+ n->relation = $9;
n->rulename = $3;
- n->event = $7;
- n->object = $9;
n->whereClause = $10;
+ n->event = $7;
n->instead = $12;
n->actions = $13;
$$ = (Node *)n;
{ $$ = (Node *)NULL; }
;
-event_object: relation_name '.' attr_name
- {
- $$ = makeNode(Attr);
- $$->relname = $1;
- $$->paramNo = NULL;
- $$->attrs = makeList1(makeString($3));
- $$->indirection = NIL;
- }
- | relation_name
- {
- $$ = makeNode(Attr);
- $$->relname = $1;
- $$->paramNo = NULL;
- $$->attrs = NIL;
- $$->indirection = NIL;
- }
- ;
-
/* change me to select, update, etc. some day */
event: SELECT { $$ = CMD_SELECT; }
| UPDATE { $$ = CMD_UPDATE; }
/*****************************************************************************
*
* QUERY:
- * NOTIFY <relation_name> can appear both in rule bodies and
+ * NOTIFY <qualified_name> can appear both in rule bodies and
* as a query-level command
*
*****************************************************************************/
-NotifyStmt: NOTIFY relation_name
+NotifyStmt: NOTIFY qualified_name
{
NotifyStmt *n = makeNode(NotifyStmt);
- n->relname = $2;
+ n->relation = $2;
$$ = (Node *)n;
}
;
-ListenStmt: LISTEN relation_name
+ListenStmt: LISTEN qualified_name
{
ListenStmt *n = makeNode(ListenStmt);
- n->relname = $2;
+ n->relation = $2;
$$ = (Node *)n;
}
-;
+ ;
-UnlistenStmt: UNLISTEN relation_name
+UnlistenStmt: UNLISTEN qualified_name
{
UnlistenStmt *n = makeNode(UnlistenStmt);
- n->relname = $2;
+ n->relation = $2;
$$ = (Node *)n;
}
| UNLISTEN '*'
{
UnlistenStmt *n = makeNode(UnlistenStmt);
- n->relname = "*";
+ n->relation = makeNode(RangeVar);
+ n->relation->relname = "*";
+ n->relation->schemaname = NULL;
$$ = (Node *)n;
}
-;
+ ;
/*****************************************************************************
*
*****************************************************************************/
-ViewStmt: CREATE VIEW name opt_column_list AS SelectStmt
+ViewStmt: CREATE VIEW qualified_name opt_column_list AS SelectStmt
{
ViewStmt *n = makeNode(ViewStmt);
- n->viewname = $3;
+ n->view = $3;
n->aliases = $4;
n->query = (Query *) $6;
$$ = (Node *)n;
*
* CREATE DATABASE
*
- *
*****************************************************************************/
CreatedbStmt: CREATE DATABASE database_name WITH createdb_opt_list
;
-/*****************************************************************************
- *
- * DROP DATABASE
- *
- *****************************************************************************/
-
-DropdbStmt: DROP DATABASE database_name
- {
- DropdbStmt *n = makeNode(DropdbStmt);
- n->dbname = $3;
- $$ = (Node *)n;
- }
- ;
-
-
/*****************************************************************************
*
* ALTER DATABASE
}
;
+
/*****************************************************************************
*
- * Manipulate a domain
+ * DROP DATABASE
+ *
+ *****************************************************************************/
+
+DropdbStmt: DROP DATABASE database_name
+ {
+ DropdbStmt *n = makeNode(DropdbStmt);
+ n->dbname = $3;
+ $$ = (Node *)n;
+ }
+ ;
+
+
+/*****************************************************************************
*
+ * Manipulate a domain
*
*****************************************************************************/
| /* EMPTY */ {$$ = FALSE; }
;
+
/*****************************************************************************
*
* QUERY:
- * cluster on <relation_name>
+ * cluster on <qualified_name>
*
*****************************************************************************/
-ClusterStmt: CLUSTER index_name ON relation_name
+ClusterStmt: CLUSTER index_name ON qualified_name
{
ClusterStmt *n = makeNode(ClusterStmt);
- n->relname = $4;
+ n->relation = $4;
n->indexname = $2;
$$ = (Node*)n;
}
n->full = $2;
n->freeze = $3;
n->verbose = $4;
- n->vacrel = NULL;
+ n->relation = NULL;
n->va_cols = NIL;
$$ = (Node *)n;
}
- | VACUUM opt_full opt_freeze opt_verbose relation_name
+ | VACUUM opt_full opt_freeze opt_verbose qualified_name
{
VacuumStmt *n = makeNode(VacuumStmt);
n->vacuum = true;
n->full = $2;
n->freeze = $3;
n->verbose = $4;
- n->vacrel = $5;
+ n->relation = $5;
n->va_cols = NIL;
$$ = (Node *)n;
}
n->full = false;
n->freeze = false;
n->verbose = $2;
- n->vacrel = NULL;
+ n->relation = NULL;
n->va_cols = NIL;
$$ = (Node *)n;
}
- | analyze_keyword opt_verbose relation_name opt_name_list
+ | analyze_keyword opt_verbose qualified_name opt_name_list
{
VacuumStmt *n = makeNode(VacuumStmt);
n->vacuum = false;
n->full = false;
n->freeze = false;
n->verbose = $2;
- n->vacrel = $3;
+ n->relation = $3;
n->va_cols = $4;
$$ = (Node *)n;
}
*
*****************************************************************************/
-/* This rule used 'opt_column_list' between 'relation_name' and 'insert_rest'
- * originally. When the second rule of 'insert_rest' was changed to use the
- * new 'SelectStmt' rule (for INTERSECT and EXCEPT) it produced a shift/reduce
- * conflict. So I just changed the rules 'InsertStmt' and 'insert_rest' to
- * accept the same statements without any shift/reduce conflicts
- */
-InsertStmt: INSERT INTO relation_name insert_rest
+InsertStmt: INSERT INTO qualified_name insert_rest
{
- $4->relname = $3;
+ $4->relation = $3;
$$ = (Node *) $4;
}
;
$$->targetList = NIL;
$$->selectStmt = $1;
}
- | '(' columnList ')' VALUES '(' target_list ')'
+ | '(' insert_column_list ')' VALUES '(' target_list ')'
{
$$ = makeNode(InsertStmt);
$$->cols = $2;
$$->targetList = $6;
$$->selectStmt = NULL;
}
- | '(' columnList ')' SelectStmt
+ | '(' insert_column_list ')' SelectStmt
{
$$ = makeNode(InsertStmt);
$$->cols = $2;
}
;
-opt_column_list: '(' columnList ')' { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
-columnList: columnList ',' columnElem
+insert_column_list: insert_column_list ',' insert_column_item
{ $$ = lappend($1, $3); }
- | columnElem
+ | insert_column_item
{ $$ = makeList1($1); }
;
-columnElem: ColId opt_indirection
+insert_column_item: ColId opt_indirection
{
- Ident *id = makeNode(Ident);
- id->name = $1;
- id->indirection = $2;
- $$ = (Node *)id;
+ ResTarget *n = makeNode(ResTarget);
+ n->name = $1;
+ n->indirection = $2;
+ n->val = NULL;
+ $$ = (Node *)n;
}
;
DeleteStmt: DELETE FROM relation_expr where_clause
{
DeleteStmt *n = makeNode(DeleteStmt);
- n->relname = $3->relname;
- n->inhOpt = $3->inhOpt;
+ n->relation = $3;
n->whereClause = $4;
$$ = (Node *)n;
}
;
-LockStmt: LOCK_P opt_table relation_name_list opt_lock
+LockStmt: LOCK_P opt_table qualified_name_list opt_lock
{
LockStmt *n = makeNode(LockStmt);
- n->rellist = $3;
+ n->relations = $3;
n->mode = $4;
$$ = (Node *)n;
}
where_clause
{
UpdateStmt *n = makeNode(UpdateStmt);
- n->relname = $2->relname;
- n->inhOpt = $2->inhOpt;
+ n->relation = $2;
n->targetList = $4;
n->fromClause = $5;
n->whereClause = $6;
SelectStmt *n = makeNode(SelectStmt);
n->distinctClause = $2;
n->targetList = $3;
- n->istemp = (bool) ((Value *) lfirst($4))->val.ival;
- n->into = (char *) lnext($4);
+ n->into = $4;
n->intoColNames = NIL;
n->fromClause = $5;
n->whereClause = $6;
}
;
- /* easy way to return two values. Can someone improve this? bjm */
into_clause: INTO OptTempTableName { $$ = $2; }
- | /*EMPTY*/ { $$ = makeList1(makeInteger(FALSE)); }
+ | /*EMPTY*/ { $$ = NULL; }
;
/*
* Redundancy here is needed to avoid shift/reduce conflicts,
* since TEMP is not a reserved word. See also OptTemp.
- *
- * The result is a cons cell (not a true list!) containing
- * a boolean and a table name.
*/
-OptTempTableName: TEMPORARY opt_table relation_name
- { $$ = lcons(makeInteger(TRUE), (List *) $3); }
- | TEMP opt_table relation_name
- { $$ = lcons(makeInteger(TRUE), (List *) $3); }
- | LOCAL TEMPORARY opt_table relation_name
- { $$ = lcons(makeInteger(TRUE), (List *) $4); }
- | LOCAL TEMP opt_table relation_name
- { $$ = lcons(makeInteger(TRUE), (List *) $4); }
- | GLOBAL TEMPORARY opt_table relation_name
+OptTempTableName: TEMPORARY opt_table qualified_name
+ {
+ $$ = $3;
+ $$->istemp = true;
+ }
+ | TEMP opt_table qualified_name
+ {
+ $$ = $3;
+ $$->istemp = true;
+ }
+ | LOCAL TEMPORARY opt_table qualified_name
+ {
+ $$ = $4;
+ $$->istemp = true;
+ }
+ | LOCAL TEMP opt_table qualified_name
+ {
+ $$ = $4;
+ $$->istemp = true;
+ }
+ | GLOBAL TEMPORARY opt_table qualified_name
{
elog(ERROR, "GLOBAL TEMPORARY TABLE is not currently supported");
- $$ = lcons(makeInteger(TRUE), (List *) $4);
+ $$ = $4;
+ $$->istemp = true;
}
- | GLOBAL TEMP opt_table relation_name
+ | GLOBAL TEMP opt_table qualified_name
{
elog(ERROR, "GLOBAL TEMPORARY TABLE is not currently supported");
- $$ = lcons(makeInteger(TRUE), (List *) $4);
+ $$ = $4;
+ $$->istemp = true;
+ }
+ | TABLE qualified_name
+ {
+ $$ = $2;
+ $$->istemp = false;
+ }
+ | qualified_name
+ {
+ $$ = $1;
+ $$->istemp = false;
}
- | TABLE relation_name
- { $$ = lcons(makeInteger(FALSE), (List *) $2); }
- | relation_name
- { $$ = lcons(makeInteger(FALSE), (List *) $1); }
;
opt_table: TABLE { $$ = TRUE; }
* ...however, recursive addattr and rename supported. make special
* cases for these.
*/
-relation_name_list: name_list;
-
-name_list: name
- { $$ = makeList1(makeString($1)); }
- | name_list ',' name
- { $$ = lappend($1, makeString($3)); }
- ;
group_clause: GROUP BY expr_list { $$ = $3; }
| /*EMPTY*/ { $$ = NIL; }
}
| relation_expr alias_clause
{
- $1->name = $2;
+ $1->alias = $2;
$$ = (Node *) $1;
}
| select_with_parens
{
RangeSubselect *n = makeNode(RangeSubselect);
n->subquery = $1;
- n->name = $2;
+ n->alias = $2;
$$ = (Node *) n;
}
| joined_table
alias_clause: AS ColId '(' name_list ')'
{
- $$ = makeNode(Attr);
- $$->relname = $2;
- $$->attrs = $4;
+ $$ = makeNode(Alias);
+ $$->aliasname = $2;
+ $$->colnames = $4;
}
| AS ColId
{
- $$ = makeNode(Attr);
- $$->relname = $2;
+ $$ = makeNode(Alias);
+ $$->aliasname = $2;
}
| ColId '(' name_list ')'
{
- $$ = makeNode(Attr);
- $$->relname = $1;
- $$->attrs = $3;
+ $$ = makeNode(Alias);
+ $$->aliasname = $1;
+ $$->colnames = $3;
}
| ColId
{
- $$ = makeNode(Attr);
- $$->relname = $1;
+ $$ = makeNode(Alias);
+ $$->aliasname = $1;
}
;
;
-relation_expr: relation_name
+relation_expr: qualified_name
{
/* default inheritance */
- $$ = makeNode(RangeVar);
- $$->relname = $1;
+ $$ = $1;
$$->inhOpt = INH_DEFAULT;
- $$->name = NULL;
+ $$->alias = NULL;
}
- | relation_name '*'
+ | qualified_name '*'
{
/* inheritance query */
- $$ = makeNode(RangeVar);
- $$->relname = $1;
+ $$ = $1;
$$->inhOpt = INH_YES;
- $$->name = NULL;
+ $$->alias = NULL;
}
- | ONLY relation_name
+ | ONLY qualified_name
{
/* no inheritance */
- $$ = makeNode(RangeVar);
- $$->relname = $2;
+ $$ = $2;
$$->inhOpt = INH_NO;
- $$->name = NULL;
+ $$->alias = NULL;
}
;
else type = xlateSqlType("bit");
$$ = type;
}
+ ;
/*
* inside parentheses, such as function arguments; that cannot introduce
* ambiguity to the b_expr syntax.
*/
-c_expr: attr
+c_expr: columnref
{ $$ = (Node *) $1; }
- | ColId opt_indirection
+ | AexprConst
+ { $$ = $1; }
+ | PARAM attrs opt_indirection
{
- /* could be a column name or a relation_name */
- Ident *n = makeNode(Ident);
- n->name = $1;
- n->indirection = $2;
+ /*
+ * PARAM without field names is considered a constant,
+ * but with 'em, it is not. Not very consistent ...
+ */
+ ParamRef *n = makeNode(ParamRef);
+ n->number = $1;
+ n->fields = $2;
+ n->indirection = $3;
$$ = (Node *)n;
}
- | AexprConst
- { $$ = $1; }
| '(' a_expr ')'
{ $$ = $2; }
+ | '(' a_expr ')' attrs opt_indirection
+ {
+ ExprFieldSelect *n = makeNode(ExprFieldSelect);
+ n->arg = $2;
+ n->fields = $4;
+ n->indirection = $5;
+ $$ = (Node *)n;
+ }
| CAST '(' a_expr AS Typename ')'
{ $$ = makeTypeCast($3, $5); }
| case_expr
{ $$ = NULL; }
;
-attr: relation_name '.' attrs opt_indirection
+/*
+ * columnref starts with relation_name not ColId, so that OLD and NEW
+ * references can be accepted. Note that when there are more than two
+ * dotted names, the first name is not actually a relation name...
+ */
+columnref: relation_name opt_indirection
{
- $$ = makeNode(Attr);
- $$->relname = $1;
- $$->paramNo = NULL;
- $$->attrs = $3;
- $$->indirection = $4;
+ $$ = makeNode(ColumnRef);
+ $$->fields = makeList1(makeString($1));
+ $$->indirection = $2;
}
- | ParamNo '.' attrs opt_indirection
+ | relation_name attrs opt_indirection
{
- $$ = makeNode(Attr);
- $$->relname = NULL;
- $$->paramNo = $1;
- $$->attrs = $3;
- $$->indirection = $4;
+ $$ = makeNode(ColumnRef);
+ $$->fields = lcons(makeString($1), $2);
+ $$->indirection = $3;
}
;
-attrs: attr_name
- { $$ = makeList1(makeString($1)); }
- | attrs '.' attr_name
+attrs: opt_attrs '.' attr_name
{ $$ = lappend($1, makeString($3)); }
- | attrs '.' '*'
+ | opt_attrs '.' '*'
{ $$ = lappend($1, makeString("*")); }
;
+opt_attrs: /*EMPTY*/
+ { $$ = NIL; }
+ | opt_attrs '.' attr_name
+ { $$ = lappend($1, makeString($3)); }
+ ;
+
opt_empty_parentheses: '(' ')' { $$ = TRUE; }
| /*EMPTY*/ { $$ = TRUE; }
+ ;
/*****************************************************************************
*
{
$$ = makeNode(ResTarget);
$$->name = $3;
- $$->indirection = NULL;
+ $$->indirection = NIL;
$$->val = (Node *)$1;
}
| a_expr
{
$$ = makeNode(ResTarget);
$$->name = NULL;
- $$->indirection = NULL;
+ $$->indirection = NIL;
$$->val = (Node *)$1;
}
- | relation_name '.' '*'
- {
- Attr *att = makeNode(Attr);
- att->relname = $1;
- att->paramNo = NULL;
- att->attrs = makeList1(makeString("*"));
- att->indirection = NIL;
- $$ = makeNode(ResTarget);
- $$->name = NULL;
- $$->indirection = NULL;
- $$->val = (Node *)att;
- }
| '*'
{
- Attr *att = makeNode(Attr);
- att->relname = "*";
- att->paramNo = NULL;
- att->attrs = NULL;
- att->indirection = NIL;
+ ColumnRef *n = makeNode(ColumnRef);
+ n->fields = makeList1(makeString("*"));
+ n->indirection = NIL;
$$ = makeNode(ResTarget);
$$->name = NULL;
- $$->indirection = NULL;
- $$->val = (Node *)att;
+ $$->indirection = NIL;
+ $$->val = (Node *)n;
}
;
$$ = $1;
}
;
+
+qualified_name_list: qualified_name
+ { $$ = makeList1($1); }
+ | qualified_name_list ',' qualified_name
+ { $$ = lappend($1, $3); }
+ ;
+
+qualified_name: ColId
+ {
+ $$ = makeNode(RangeVar);
+ $$->catalogname = NULL;
+ $$->schemaname = NULL;
+ $$->relname = $1;
+ }
+ | ColId '.' ColId
+ {
+ $$ = makeNode(RangeVar);
+ $$->catalogname = NULL;
+ $$->schemaname = $1;
+ $$->relname = $3;
+ }
+ | ColId '.' ColId '.' ColId
+ {
+ $$ = makeNode(RangeVar);
+ $$->catalogname = $1;
+ $$->schemaname = $3;
+ $$->relname = $5;
+ }
+ ;
+
+name_list: name
+ { $$ = makeList1(makeString($1)); }
+ | name_list ',' name
+ { $$ = lappend($1, makeString($3)); }
+ ;
+
name: ColId { $$ = $1; };
database_name: ColId { $$ = $1; };
$$ = (Node *)n;
}
- | ParamNo
- { $$ = (Node *)$1; }
+ | PARAM opt_indirection
+ {
+ ParamRef *n = makeNode(ParamRef);
+ n->number = $1;
+ n->fields = NIL;
+ n->indirection = $2;
+ $$ = (Node *)n;
+ }
| TRUE_P
{
A_Const *n = makeNode(A_Const);
}
;
-ParamNo: PARAM opt_indirection
- {
- $$ = makeNode(ParamNo);
- $$->number = $1;
- $$->indirection = $2;
- }
- ;
-
Iconst: ICONST { $$ = $1; };
Sconst: SCONST { $$ = $1; };
UserId: ColId { $$ = $1; };
| AGGREGATE { $$ = "aggregate"; }
| ALTER { $$ = "alter"; }
| AT { $$ = "at"; }
- | AUTHORIZATION { $$ = "authorization"; }
| BACKWARD { $$ = "backward"; }
| BEFORE { $$ = "before"; }
| BEGIN_TRANS { $$ = "begin"; }
| COMMITTED { $$ = "committed"; }
| CONSTRAINTS { $$ = "constraints"; }
| COPY { $$ = "copy"; }
- | CREATE { $$ = "create"; }
| CREATEDB { $$ = "createdb"; }
| CREATEUSER { $$ = "createuser"; }
| CURSOR { $$ = "cursor"; }
| FORWARD { $$ = "forward"; }
| FUNCTION { $$ = "function"; }
| GLOBAL { $$ = "global"; }
- | GRANT { $$ = "grant"; }
| HANDLER { $$ = "handler"; }
| HOUR_P { $$ = "hour"; }
| IMMEDIATE { $$ = "immediate"; }
* - thomas 2000-11-28
*/
func_name_keyword:
- BETWEEN { $$ = "between"; }
+ AUTHORIZATION { $$ = "authorization"; }
+ | BETWEEN { $$ = "between"; }
| BINARY { $$ = "binary"; }
| CROSS { $$ = "cross"; }
| FREEZE { $$ = "freeze"; }
| COLLATE { $$ = "collate"; }
| COLUMN { $$ = "column"; }
| CONSTRAINT { $$ = "constraint"; }
+ | CREATE { $$ = "create"; }
| CURRENT_DATE { $$ = "current_date"; }
| CURRENT_TIME { $$ = "current_time"; }
| CURRENT_TIMESTAMP { $$ = "current_timestamp"; }