1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* makefuncs.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* creator functions for primitive nodes. The functions here are for
|
|
|
|
* the most frequently created nodes.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-04-12 19:17:23 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.21 2000/04/12 17:15:16 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
1997-09-07 07:04:48 +02:00
|
|
|
* Creator functions in POSTGRES 4.2 are generated automatically. Most of
|
|
|
|
* them are rarely used. Now we don't generate them any more. If you want
|
|
|
|
* one, you have to write it yourself.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* HISTORY
|
1997-09-07 07:04:48 +02:00
|
|
|
* AUTHOR DATE MAJOR EVENT
|
|
|
|
* Andrew Yu Oct 20, 1994 file creation
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
#include "nodes/makefuncs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeOper -
|
1997-09-07 07:04:48 +02:00
|
|
|
* creates an Oper node
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
Oper *
|
1996-07-09 08:22:35 +02:00
|
|
|
makeOper(Oid opno,
|
1997-09-07 07:04:48 +02:00
|
|
|
Oid opid,
|
|
|
|
Oid opresulttype,
|
|
|
|
int opsize,
|
|
|
|
FunctionCachePtr op_fcache)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Oper *oper = makeNode(Oper);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
oper->opno = opno;
|
|
|
|
oper->opid = opid;
|
|
|
|
oper->opresulttype = opresulttype;
|
|
|
|
oper->opsize = opsize;
|
|
|
|
oper->op_fcache = op_fcache;
|
|
|
|
return oper;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeVar -
|
1997-09-07 07:04:48 +02:00
|
|
|
* creates a Var node
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
Var *
|
1997-09-07 07:04:48 +02:00
|
|
|
makeVar(Index varno,
|
|
|
|
AttrNumber varattno,
|
|
|
|
Oid vartype,
|
1998-07-12 23:29:40 +02:00
|
|
|
int32 vartypmod,
|
1999-08-22 22:15:04 +02:00
|
|
|
Index varlevelsup)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Var *var = makeNode(Var);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
var->varno = varno;
|
|
|
|
var->varattno = varattno;
|
|
|
|
var->vartype = vartype;
|
1998-02-10 05:02:59 +01:00
|
|
|
var->vartypmod = vartypmod;
|
1998-01-20 23:12:17 +01:00
|
|
|
var->varlevelsup = varlevelsup;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
1999-08-22 22:15:04 +02:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Since few if any routines ever create Var nodes with
|
|
|
|
* varnoold/varoattno different from varno/varattno, we don't provide
|
|
|
|
* separate arguments for them, but just initialize them to the given
|
|
|
|
* varno/varattno. This reduces code clutter and chance of error for
|
|
|
|
* most callers.
|
1999-08-22 22:15:04 +02:00
|
|
|
*/
|
|
|
|
var->varnoold = varno;
|
|
|
|
var->varoattno = varattno;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
return var;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1998-07-20 21:53:53 +02:00
|
|
|
/*
|
|
|
|
* makeTargetEntry -
|
|
|
|
* creates a TargetEntry node(contains a Resdom)
|
|
|
|
*/
|
|
|
|
TargetEntry *
|
|
|
|
makeTargetEntry(Resdom *resdom, Node *expr)
|
|
|
|
{
|
|
|
|
TargetEntry *rt = makeNode(TargetEntry);
|
|
|
|
|
|
|
|
rt->resdom = resdom;
|
|
|
|
rt->expr = expr;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
|
|
|
* makeResdom -
|
1997-09-07 07:04:48 +02:00
|
|
|
* creates a Resdom (Result Domain) node
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
Resdom *
|
1996-07-09 08:22:35 +02:00
|
|
|
makeResdom(AttrNumber resno,
|
1997-09-07 07:04:48 +02:00
|
|
|
Oid restype,
|
1998-07-12 23:29:40 +02:00
|
|
|
int32 restypmod,
|
1997-09-07 07:04:48 +02:00
|
|
|
char *resname,
|
|
|
|
Index reskey,
|
|
|
|
Oid reskeyop,
|
1999-05-17 19:03:51 +02:00
|
|
|
bool resjunk)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Resdom *resdom = makeNode(Resdom);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
resdom->resno = resno;
|
|
|
|
resdom->restype = restype;
|
1998-02-10 05:02:59 +01:00
|
|
|
resdom->restypmod = restypmod;
|
1997-09-07 07:04:48 +02:00
|
|
|
resdom->resname = resname;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For historical reasons, ressortgroupref defaults to 0 while
|
1999-08-21 05:49:17 +02:00
|
|
|
* reskey/reskeyop are passed in explicitly. This is pretty silly.
|
|
|
|
*/
|
|
|
|
resdom->ressortgroupref = 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
resdom->reskey = reskey;
|
|
|
|
resdom->reskeyop = reskeyop;
|
|
|
|
resdom->resjunk = resjunk;
|
|
|
|
return resdom;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeConst -
|
1997-09-07 07:04:48 +02:00
|
|
|
* creates a Const node
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
Const *
|
1996-07-09 08:22:35 +02:00
|
|
|
makeConst(Oid consttype,
|
1998-02-21 17:58:49 +01:00
|
|
|
int constlen,
|
1997-09-07 07:04:48 +02:00
|
|
|
Datum constvalue,
|
|
|
|
bool constisnull,
|
|
|
|
bool constbyval,
|
|
|
|
bool constisset,
|
|
|
|
bool constiscast)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Const *cnst = makeNode(Const);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
cnst->consttype = consttype;
|
|
|
|
cnst->constlen = constlen;
|
|
|
|
cnst->constvalue = constvalue;
|
|
|
|
cnst->constisnull = constisnull;
|
|
|
|
cnst->constbyval = constbyval;
|
|
|
|
cnst->constisset = constisset;
|
|
|
|
cnst->constiscast = constiscast;
|
|
|
|
return cnst;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2000-02-15 04:38:29 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeAttr -
|
|
|
|
* creates an Attr node
|
|
|
|
*/
|
|
|
|
Attr *
|
|
|
|
makeAttr(char *relname, char *attname)
|
|
|
|
{
|
|
|
|
Attr *a = makeNode(Attr);
|
|
|
|
|
|
|
|
a->relname = pstrdup(relname);
|
|
|
|
a->paramNo = NULL;
|
|
|
|
if (attname != NULL)
|
|
|
|
a->attrs = lcons(makeString(pstrdup(attname)), NIL);
|
|
|
|
a->indirection = NULL;
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|