ObjectWithArgs *func = (ObjectWithArgs *) lfirst(cell);
Oid funcid;
- funcid = LookupFuncNameTypeNames(func->objname,
- func->objargs, false);
+ funcid = LookupFuncWithArgs(func, false);
objects = lappend_oid(objects, funcid);
}
break;
address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
break;
case OBJECT_AGGREGATE:
- {
- ObjectWithArgs *owa = castNode(ObjectWithArgs, object);
- address.classId = ProcedureRelationId;
- address.objectId =
- LookupAggNameTypeNames(owa->objname, owa->objargs, missing_ok);
- address.objectSubId = 0;
- break;
- }
+ address.classId = ProcedureRelationId;
+ address.objectId = LookupAggWithArgs(castNode(ObjectWithArgs, object), missing_ok);
+ address.objectSubId = 0;
+ break;
case OBJECT_FUNCTION:
- {
- ObjectWithArgs *owa = castNode(ObjectWithArgs, object);
- address.classId = ProcedureRelationId;
- address.objectId =
- LookupFuncNameTypeNames(owa->objname, owa->objargs, missing_ok);
- address.objectSubId = 0;
- break;
- }
+ address.classId = ProcedureRelationId;
+ address.objectId = LookupFuncWithArgs(castNode(ObjectWithArgs, object), missing_ok);
+ address.objectSubId = 0;
+ break;
case OBJECT_OPERATOR:
- {
- ObjectWithArgs *owa = castNode(ObjectWithArgs, object);
- address.classId = OperatorRelationId;
- Assert(list_length(owa->objargs) == 2);
- address.objectId =
- LookupOperNameTypeNames(NULL, owa->objname,
- castNode(TypeName, linitial(owa->objargs)),
- castNode(TypeName, lsecond(owa->objargs)),
- missing_ok, -1);
- address.objectSubId = 0;
- break;
- }
+ address.classId = OperatorRelationId;
+ address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
+ address.objectSubId = 0;
+ break;
case OBJECT_COLLATION:
address.classId = CollationRelationId;
address.objectId = get_collation_oid(castNode(List, object), missing_ok);
rel = heap_open(ProcedureRelationId, RowExclusiveLock);
- funcOid = LookupFuncNameTypeNames(stmt->func->objname,
- stmt->func->objargs,
- false);
+ funcOid = LookupFuncWithArgs(stmt->func, false);
tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(funcOid));
if (!HeapTupleIsValid(tup)) /* should not happen */
{
Form_pg_proc procstruct;
- funcid = LookupFuncNameTypeNames(stmt->func->objname,
- stmt->func->objargs,
- false);
+ funcid = LookupFuncWithArgs(stmt->func, false);
tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
if (!HeapTupleIsValid(tuple))
*/
if (stmt->fromsql)
{
- fromsqlfuncid = LookupFuncNameTypeNames(stmt->fromsql->objname, stmt->fromsql->objargs, false);
+ fromsqlfuncid = LookupFuncWithArgs(stmt->fromsql, false);
if (!pg_proc_ownercheck(fromsqlfuncid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC, NameListToString(stmt->fromsql->objname));
if (stmt->tosql)
{
- tosqlfuncid = LookupFuncNameTypeNames(stmt->tosql->objname, stmt->tosql->objargs, false);
+ tosqlfuncid = LookupFuncWithArgs(stmt->tosql, false);
if (!pg_proc_ownercheck(tosqlfuncid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC, NameListToString(stmt->tosql->objname));
errmsg("invalid operator number %d,"
" must be between 1 and %d",
item->number, maxOpNumber)));
- if (item->args != NIL)
- {
- TypeName *typeName1 = (TypeName *) linitial(item->args);
- TypeName *typeName2 = (TypeName *) lsecond(item->args);
-
- operOid = LookupOperNameTypeNames(NULL, item->name,
- typeName1, typeName2,
- false, -1);
- }
+ if (item->name->objargs != NIL)
+ operOid = LookupOperWithArgs(item->name, false);
else
{
/* Default to binary op on input datatype */
- operOid = LookupOperName(NULL, item->name,
+ operOid = LookupOperName(NULL, item->name->objname,
typeoid, typeoid,
false, -1);
}
errmsg("invalid procedure number %d,"
" must be between 1 and %d",
item->number, maxProcNumber)));
- funcOid = LookupFuncNameTypeNames(item->name, item->args,
- false);
+ funcOid = LookupFuncWithArgs(item->name, false);
#ifdef NOT_USED
/* XXX this is unnecessary given the superuser check above */
/* Caller must own function */
errmsg("invalid operator number %d,"
" must be between 1 and %d",
item->number, maxOpNumber)));
- if (item->args != NIL)
- {
- TypeName *typeName1 = (TypeName *) linitial(item->args);
- TypeName *typeName2 = (TypeName *) lsecond(item->args);
-
- operOid = LookupOperNameTypeNames(NULL, item->name,
- typeName1, typeName2,
- false, -1);
- }
+ if (item->name->objargs != NIL)
+ operOid = LookupOperWithArgs(item->name, false);
else
{
ereport(ERROR,
errmsg("invalid procedure number %d,"
" must be between 1 and %d",
item->number, maxProcNumber)));
- funcOid = LookupFuncNameTypeNames(item->name, item->args,
- false);
+ funcOid = LookupFuncWithArgs(item->name, false);
#ifdef NOT_USED
/* XXX this is unnecessary given the superuser check above */
/* Caller must own function */
Oid joinOid;
/* Look up the operator */
- oprId = LookupOperNameTypeNames(NULL, stmt->opername,
- (TypeName *) linitial(stmt->operargs),
- (TypeName *) lsecond(stmt->operargs),
- false, -1);
+ oprId = LookupOperWithArgs(stmt->opername, false);
catalog = heap_open(OperatorRelationId, RowExclusiveLock);
tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(oprId));
if (tup == NULL)
AlterOperatorStmt *newnode = makeNode(AlterOperatorStmt);
COPY_NODE_FIELD(opername);
- COPY_NODE_FIELD(operargs);
COPY_NODE_FIELD(options);
return newnode;
COPY_SCALAR_FIELD(itemtype);
COPY_NODE_FIELD(name);
- COPY_NODE_FIELD(args);
COPY_SCALAR_FIELD(number);
COPY_NODE_FIELD(order_family);
COPY_NODE_FIELD(class_args);
_equalAlterOperatorStmt(const AlterOperatorStmt *a, const AlterOperatorStmt *b)
{
COMPARE_NODE_FIELD(opername);
- COMPARE_NODE_FIELD(operargs);
COMPARE_NODE_FIELD(options);
return true;
{
COMPARE_SCALAR_FIELD(itemtype);
COMPARE_NODE_FIELD(name);
- COMPARE_NODE_FIELD(args);
COMPARE_SCALAR_FIELD(number);
COMPARE_NODE_FIELD(order_family);
COMPARE_NODE_FIELD(class_args);
OPERATOR Iconst any_operator opclass_purpose opt_recheck
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
+ ObjectWithArgs *owa = makeNode(ObjectWithArgs);
+ owa->objname = $3;
+ owa->objargs = NIL;
n->itemtype = OPCLASS_ITEM_OPERATOR;
- n->name = $3;
- n->args = NIL;
+ n->name = owa;
n->number = $2;
n->order_family = $4;
$$ = (Node *) n;
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
n->itemtype = OPCLASS_ITEM_OPERATOR;
- n->name = $3->objname;
- n->args = $3->objargs;
+ n->name = $3;
n->number = $2;
n->order_family = $4;
$$ = (Node *) n;
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
n->itemtype = OPCLASS_ITEM_FUNCTION;
- n->name = $3->objname;
- n->args = $3->objargs;
+ n->name = $3;
n->number = $2;
$$ = (Node *) n;
}
{
CreateOpClassItem *n = makeNode(CreateOpClassItem);
n->itemtype = OPCLASS_ITEM_FUNCTION;
- n->name = $6->objname;
- n->args = $6->objargs;
+ n->name = $6;
n->number = $2;
n->class_args = $4;
$$ = (Node *) n;
ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
{
AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
- n->opername = $3->objname;
- n->operargs = $3->objargs;
+ n->opername = $3;
n->options = $6;
$$ = (Node *)n;
}
}
/*
- * LookupFuncNameTypeNames
+ * LookupFuncWithArgs
* Like LookupFuncName, but the argument types are specified by a
- * list of TypeName nodes.
+ * ObjectWithArgs node.
*/
Oid
-LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
+LookupFuncWithArgs(ObjectWithArgs *func, bool noError)
{
Oid argoids[FUNC_MAX_ARGS];
int argcount;
int i;
ListCell *args_item;
- argcount = list_length(argtypes);
+ argcount = list_length(func->objargs);
if (argcount > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
FUNC_MAX_ARGS,
FUNC_MAX_ARGS)));
- args_item = list_head(argtypes);
+ args_item = list_head(func->objargs);
for (i = 0; i < argcount; i++)
{
TypeName *t = (TypeName *) lfirst(args_item);
args_item = lnext(args_item);
}
- return LookupFuncName(funcname, argcount, argoids, noError);
+ return LookupFuncName(func->objname, argcount, argoids, noError);
}
/*
- * LookupAggNameTypeNames
- * Find an aggregate function given a name and list of TypeName nodes.
+ * LookupAggWithArgs
+ * Find an aggregate function from a given ObjectWithArgs node.
*
- * This is almost like LookupFuncNameTypeNames, but the error messages refer
+ * This is almost like LookupFuncWithArgs, but the error messages refer
* to aggregates rather than plain functions, and we verify that the found
* function really is an aggregate.
*/
Oid
-LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
+LookupAggWithArgs(ObjectWithArgs *agg, bool noError)
{
Oid argoids[FUNC_MAX_ARGS];
int argcount;
HeapTuple ftup;
Form_pg_proc pform;
- argcount = list_length(argtypes);
+ argcount = list_length(agg->objargs);
if (argcount > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
FUNC_MAX_ARGS)));
i = 0;
- foreach(lc, argtypes)
+ foreach(lc, agg->objargs)
{
TypeName *t = (TypeName *) lfirst(lc);
i++;
}
- oid = LookupFuncName(aggname, argcount, argoids, true);
+ oid = LookupFuncName(agg->objname, argcount, argoids, true);
if (!OidIsValid(oid))
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("aggregate %s(*) does not exist",
- NameListToString(aggname))));
+ NameListToString(agg->objname))));
else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("aggregate %s does not exist",
- func_signature_string(aggname, argcount,
+ func_signature_string(agg->objname, argcount,
NIL, argoids))));
}
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function %s is not an aggregate",
- func_signature_string(aggname, argcount,
+ func_signature_string(agg->objname, argcount,
NIL, argoids))));
}
}
/*
- * LookupOperNameTypeNames
+ * LookupOperWithArgs
* Like LookupOperName, but the argument types are specified by
- * TypeName nodes.
- *
- * Pass oprleft = NULL for a prefix op, oprright = NULL for a postfix op.
+ * a ObjectWithArg node.
*/
Oid
-LookupOperNameTypeNames(ParseState *pstate, List *opername,
- TypeName *oprleft, TypeName *oprright,
- bool noError, int location)
+LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
{
+ TypeName *oprleft,
+ *oprright;
Oid leftoid,
rightoid;
+ Assert(list_length(oper->objargs) == 2);
+ oprleft = linitial(oper->objargs);
+ oprright = lsecond(oper->objargs);
+
if (oprleft == NULL)
leftoid = InvalidOid;
else
- leftoid = LookupTypeNameOid(pstate, oprleft, noError);
+ leftoid = LookupTypeNameOid(NULL, oprleft, noError);
if (oprright == NULL)
rightoid = InvalidOid;
else
- rightoid = LookupTypeNameOid(pstate, oprright, noError);
+ rightoid = LookupTypeNameOid(NULL, oprright, noError);
- return LookupOperName(pstate, opername, leftoid, rightoid,
- noError, location);
+ return LookupOperName(NULL, oper->objname, leftoid, rightoid,
+ noError, -1);
}
/*
{
NodeTag type;
int itemtype; /* see codes above */
- /* fields used for an operator or function item: */
- List *name; /* operator or function name */
- List *args; /* argument types */
+ ObjectWithArgs *name; /* operator or function name and args */
int number; /* strategy num or support proc num */
List *order_family; /* only used for ordering operators */
List *class_args; /* amproclefttype/amprocrighttype or
typedef struct AlterOperatorStmt
{
NodeTag type;
- List *opername; /* operator name */
- List *operargs; /* operator's argument TypeNames */
+ ObjectWithArgs *opername; /* operator name and argument types */
List *options; /* List of DefElem nodes */
} AlterOperatorStmt;
extern Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes,
bool noError);
-extern Oid LookupFuncNameTypeNames(List *funcname, List *argtypes,
+extern Oid LookupFuncWithArgs(ObjectWithArgs *func,
bool noError);
-extern Oid LookupAggNameTypeNames(List *aggname, List *argtypes,
+extern Oid LookupAggWithArgs(ObjectWithArgs *agg,
bool noError);
extern void check_srf_call_placement(ParseState *pstate, int location);
#define PARSE_OPER_H
#include "access/htup.h"
+#include "nodes/parsenodes.h"
#include "parser/parse_node.h"
extern Oid LookupOperName(ParseState *pstate, List *opername,
Oid oprleft, Oid oprright,
bool noError, int location);
-extern Oid LookupOperNameTypeNames(ParseState *pstate, List *opername,
- TypeName *oprleft, TypeName *oprright,
- bool noError, int location);
+extern Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError);
/* Routines to find operators matching a name and given input types */
/* NB: the selected operator may require coercion of the input types! */