1996-07-09 06:22:35 +00:00
|
|
|
/*
|
1999-02-13 23:22:53 +00:00
|
|
|
* makefuncs.c
|
1997-09-07 05:04:48 +00:00
|
|
|
* creator functions for primitive nodes. The functions here are for
|
|
|
|
* the most frequently created nodes.
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
2001-01-24 19:43:33 +00:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 05:58:53 +00:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2001-03-22 04:01:46 +00:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.26 2001/03/22 03:59:32 momjian Exp $
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
1997-09-07 05:04:48 +00: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 06:22:35 +00:00
|
|
|
*
|
|
|
|
* HISTORY
|
1997-09-07 05:04:48 +00:00
|
|
|
* AUTHOR DATE MAJOR EVENT
|
|
|
|
* Andrew Yu Oct 20, 1994 file creation
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
2000-11-16 22:30:52 +00:00
|
|
|
|
1996-07-09 06:22:35 +00:00
|
|
|
#include "nodes/makefuncs.h"
|
2000-11-16 22:30:52 +00:00
|
|
|
#include "utils/lsyscache.h"
|
|
|
|
|
1996-07-09 06:22:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeOper -
|
1997-09-07 05:04:48 +00:00
|
|
|
* creates an Oper node
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
1998-02-26 04:46:47 +00:00
|
|
|
Oper *
|
1996-07-09 06:22:35 +00:00
|
|
|
makeOper(Oid opno,
|
1997-09-07 05:04:48 +00:00
|
|
|
Oid opid,
|
2000-08-08 15:43:12 +00:00
|
|
|
Oid opresulttype)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1997-09-08 02:41:22 +00:00
|
|
|
Oper *oper = makeNode(Oper);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
oper->opno = opno;
|
|
|
|
oper->opid = opid;
|
|
|
|
oper->opresulttype = opresulttype;
|
2000-08-08 15:43:12 +00:00
|
|
|
oper->op_fcache = NULL;
|
1997-09-07 05:04:48 +00:00
|
|
|
return oper;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeVar -
|
1997-09-07 05:04:48 +00:00
|
|
|
* creates a Var node
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
*/
|
1998-02-26 04:46:47 +00:00
|
|
|
Var *
|
1997-09-07 05:04:48 +00:00
|
|
|
makeVar(Index varno,
|
|
|
|
AttrNumber varattno,
|
|
|
|
Oid vartype,
|
1998-07-12 21:29:40 +00:00
|
|
|
int32 vartypmod,
|
1999-08-22 20:15:04 +00:00
|
|
|
Index varlevelsup)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1997-09-08 02:41:22 +00:00
|
|
|
Var *var = makeNode(Var);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
var->varno = varno;
|
|
|
|
var->varattno = varattno;
|
|
|
|
var->vartype = vartype;
|
1998-02-10 04:02:59 +00:00
|
|
|
var->vartypmod = vartypmod;
|
1998-01-20 22:12:17 +00:00
|
|
|
var->varlevelsup = varlevelsup;
|
2000-04-12 17:17:23 +00:00
|
|
|
|
1999-08-22 20:15:04 +00:00
|
|
|
/*
|
2000-04-12 17:17:23 +00: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 20:15:04 +00:00
|
|
|
*/
|
|
|
|
var->varnoold = varno;
|
|
|
|
var->varoattno = varattno;
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
return var;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
1998-07-20 19:53:53 +00: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 06:22:35 +00:00
|
|
|
/*
|
|
|
|
* makeResdom -
|
1997-09-07 05:04:48 +00:00
|
|
|
* creates a Resdom (Result Domain) node
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
1998-02-26 04:46:47 +00:00
|
|
|
Resdom *
|
1996-07-09 06:22:35 +00:00
|
|
|
makeResdom(AttrNumber resno,
|
1997-09-07 05:04:48 +00:00
|
|
|
Oid restype,
|
1998-07-12 21:29:40 +00:00
|
|
|
int32 restypmod,
|
1997-09-07 05:04:48 +00:00
|
|
|
char *resname,
|
1999-05-17 17:03:51 +00:00
|
|
|
bool resjunk)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1997-09-08 02:41:22 +00:00
|
|
|
Resdom *resdom = makeNode(Resdom);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
resdom->resno = resno;
|
|
|
|
resdom->restype = restype;
|
1998-02-10 04:02:59 +00:00
|
|
|
resdom->restypmod = restypmod;
|
1997-09-07 05:04:48 +00:00
|
|
|
resdom->resname = resname;
|
2000-04-12 17:17:23 +00:00
|
|
|
|
|
|
|
/*
|
2001-03-22 04:01:46 +00:00
|
|
|
* We always set the sorting/grouping fields to 0. If the caller
|
|
|
|
* wants to change them he must do so explicitly. Few if any callers
|
|
|
|
* should be doing that, so omitting these arguments reduces the
|
|
|
|
* chance of error.
|
1999-08-21 03:49:17 +00:00
|
|
|
*/
|
|
|
|
resdom->ressortgroupref = 0;
|
2000-08-08 15:43:12 +00:00
|
|
|
resdom->reskey = 0;
|
|
|
|
resdom->reskeyop = InvalidOid;
|
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
resdom->resjunk = resjunk;
|
|
|
|
return resdom;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeConst -
|
1997-09-07 05:04:48 +00:00
|
|
|
* creates a Const node
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
1998-02-26 04:46:47 +00:00
|
|
|
Const *
|
1996-07-09 06:22:35 +00:00
|
|
|
makeConst(Oid consttype,
|
1998-02-21 16:58:49 +00:00
|
|
|
int constlen,
|
1997-09-07 05:04:48 +00:00
|
|
|
Datum constvalue,
|
|
|
|
bool constisnull,
|
|
|
|
bool constbyval,
|
|
|
|
bool constisset,
|
|
|
|
bool constiscast)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1997-09-08 02:41:22 +00:00
|
|
|
Const *cnst = makeNode(Const);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00: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 06:22:35 +00:00
|
|
|
}
|
2000-02-15 03:38:29 +00:00
|
|
|
|
2000-11-16 22:30:52 +00:00
|
|
|
/*
|
|
|
|
* makeNullConst -
|
|
|
|
* creates a Const node representing a NULL of the specified type
|
|
|
|
*/
|
|
|
|
Const *
|
|
|
|
makeNullConst(Oid consttype)
|
|
|
|
{
|
|
|
|
int16 typLen;
|
|
|
|
bool typByVal;
|
|
|
|
|
|
|
|
get_typlenbyval(consttype, &typLen, &typByVal);
|
|
|
|
return makeConst(consttype,
|
|
|
|
(int) typLen,
|
|
|
|
(Datum) 0,
|
|
|
|
true,
|
|
|
|
typByVal,
|
|
|
|
false,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
2000-02-15 03:38:29 +00: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)
|
2001-01-17 17:26:45 +00:00
|
|
|
a->attrs = makeList1(makeString(pstrdup(attname)));
|
2000-02-15 03:38:29 +00:00
|
|
|
a->indirection = NULL;
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|