2002-12-12 15:49:42 +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
|
|
|
*
|
2003-08-04 02:40:20 +00:00
|
|
|
* Portions Copyright (c) 1996-2003, 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
|
2003-11-29 19:52:15 +00:00
|
|
|
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.42 2003/11/29 19:51:49 pgsql Exp $
|
2002-12-12 15:49:42 +00:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
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
|
|
|
|
2002-04-16 23:08:12 +00:00
|
|
|
/*
|
|
|
|
* makeA_Expr -
|
|
|
|
* makes an A_Expr node
|
|
|
|
*/
|
|
|
|
A_Expr *
|
2003-02-10 04:44:47 +00:00
|
|
|
makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr)
|
2002-04-16 23:08:12 +00:00
|
|
|
{
|
|
|
|
A_Expr *a = makeNode(A_Expr);
|
|
|
|
|
2003-02-10 04:44:47 +00:00
|
|
|
a->kind = kind;
|
2002-04-16 23:08:12 +00:00
|
|
|
a->name = name;
|
|
|
|
a->lexpr = lexpr;
|
|
|
|
a->rexpr = rexpr;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeSimpleA_Expr -
|
|
|
|
* As above, given a simple (unqualified) operator name
|
|
|
|
*/
|
|
|
|
A_Expr *
|
2003-02-10 04:44:47 +00:00
|
|
|
makeSimpleA_Expr(A_Expr_Kind kind, const char *name,
|
2002-04-16 23:08:12 +00:00
|
|
|
Node *lexpr, Node *rexpr)
|
|
|
|
{
|
|
|
|
A_Expr *a = makeNode(A_Expr);
|
|
|
|
|
2003-02-10 04:44:47 +00:00
|
|
|
a->kind = kind;
|
2002-04-16 23:08:12 +00:00
|
|
|
a->name = makeList1(makeString((char *) name));
|
|
|
|
a->lexpr = lexpr;
|
|
|
|
a->rexpr = rexpr;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
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 -
|
2002-12-12 15:49:42 +00:00
|
|
|
* creates a TargetEntry node (contains a Resdom)
|
1998-07-20 19:53:53 +00:00
|
|
|
*/
|
|
|
|
TargetEntry *
|
2002-12-12 15:49:42 +00:00
|
|
|
makeTargetEntry(Resdom *resdom, Expr *expr)
|
1998-07-20 19:53:53 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
2003-05-06 00:20:33 +00:00
|
|
|
* We always set these fields to 0. If the caller wants to change them
|
|
|
|
* he must do so explicitly. Few callers do that, so omitting these
|
|
|
|
* arguments reduces the chance of error.
|
1999-08-21 03:49:17 +00:00
|
|
|
*/
|
|
|
|
resdom->ressortgroupref = 0;
|
2003-05-06 00:20:33 +00:00
|
|
|
resdom->resorigtbl = InvalidOid;
|
|
|
|
resdom->resorigcol = 0;
|
2000-08-08 15:43:12 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
resdom->resjunk = resjunk;
|
2003-05-06 00:20:33 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
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,
|
2002-11-25 21:29:42 +00:00
|
|
|
bool constbyval)
|
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;
|
2002-11-25 21:29:42 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
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,
|
2002-11-25 21:29:42 +00:00
|
|
|
typByVal);
|
2000-11-16 22:30:52 +00:00
|
|
|
}
|
|
|
|
|
2002-12-12 15:49:42 +00:00
|
|
|
/*
|
|
|
|
* makeBoolExpr -
|
|
|
|
* creates a BoolExpr node
|
|
|
|
*/
|
|
|
|
Expr *
|
|
|
|
makeBoolExpr(BoolExprType boolop, List *args)
|
|
|
|
{
|
|
|
|
BoolExpr *b = makeNode(BoolExpr);
|
|
|
|
|
|
|
|
b->boolop = boolop;
|
|
|
|
b->args = args;
|
|
|
|
|
|
|
|
return (Expr *) b;
|
|
|
|
}
|
|
|
|
|
2000-02-15 03:38:29 +00:00
|
|
|
/*
|
2002-03-21 16:02:16 +00:00
|
|
|
* makeAlias -
|
|
|
|
* creates an Alias node
|
|
|
|
*
|
|
|
|
* NOTE: the given name is copied, but the colnames list (if any) isn't.
|
2000-02-15 03:38:29 +00:00
|
|
|
*/
|
2002-03-21 16:02:16 +00:00
|
|
|
Alias *
|
|
|
|
makeAlias(const char *aliasname, List *colnames)
|
2000-02-15 03:38:29 +00:00
|
|
|
{
|
2002-03-21 16:02:16 +00:00
|
|
|
Alias *a = makeNode(Alias);
|
2000-02-15 03:38:29 +00:00
|
|
|
|
2002-03-21 16:02:16 +00:00
|
|
|
a->aliasname = pstrdup(aliasname);
|
|
|
|
a->colnames = colnames;
|
2000-02-15 03:38:29 +00:00
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
2002-03-20 19:45:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeRelabelType -
|
|
|
|
* creates a RelabelType node
|
|
|
|
*/
|
|
|
|
RelabelType *
|
2002-12-12 15:49:42 +00:00
|
|
|
makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, CoercionForm rformat)
|
2002-03-20 19:45:13 +00:00
|
|
|
{
|
|
|
|
RelabelType *r = makeNode(RelabelType);
|
|
|
|
|
|
|
|
r->arg = arg;
|
|
|
|
r->resulttype = rtype;
|
|
|
|
r->resulttypmod = rtypmod;
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 21:35:25 +00:00
|
|
|
r->relabelformat = rformat;
|
2002-03-20 19:45:13 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2002-03-22 02:56:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeRangeVar -
|
|
|
|
* creates a RangeVar node (rather oversimplified case)
|
|
|
|
*/
|
|
|
|
RangeVar *
|
|
|
|
makeRangeVar(char *schemaname, char *relname)
|
|
|
|
{
|
2002-09-04 20:31:48 +00:00
|
|
|
RangeVar *r = makeNode(RangeVar);
|
2002-03-22 02:56:37 +00:00
|
|
|
|
|
|
|
r->catalogname = NULL;
|
|
|
|
r->schemaname = schemaname;
|
|
|
|
r->relname = relname;
|
|
|
|
r->inhOpt = INH_DEFAULT;
|
|
|
|
r->istemp = false;
|
|
|
|
r->alias = NULL;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2002-03-29 19:06:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeTypeName -
|
|
|
|
* build a TypeName node for an unqualified name.
|
|
|
|
*/
|
|
|
|
TypeName *
|
|
|
|
makeTypeName(char *typnam)
|
|
|
|
{
|
|
|
|
TypeName *n = makeNode(TypeName);
|
|
|
|
|
|
|
|
n->names = makeList1(makeString(typnam));
|
|
|
|
n->typmod = -1;
|
|
|
|
return n;
|
|
|
|
}
|
2003-07-01 19:10:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeFuncExpr -
|
|
|
|
* build an expression tree representing a function call.
|
|
|
|
*
|
|
|
|
* The argument expressions must have been transformed already.
|
|
|
|
*/
|
|
|
|
FuncExpr *
|
|
|
|
makeFuncExpr(Oid funcid, Oid rettype, List *args, CoercionForm fformat)
|
|
|
|
{
|
|
|
|
FuncExpr *funcexpr;
|
|
|
|
|
|
|
|
funcexpr = makeNode(FuncExpr);
|
|
|
|
funcexpr->funcid = funcid;
|
|
|
|
funcexpr->funcresulttype = rettype;
|
|
|
|
funcexpr->funcretset = false; /* only allowed case here */
|
|
|
|
funcexpr->funcformat = fformat;
|
|
|
|
funcexpr->args = args;
|
|
|
|
|
|
|
|
return funcexpr;
|
|
|
|
}
|