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
|
|
|
*
|
2013-01-01 17:15:01 -05:00
|
|
|
* Portions Copyright (c) 1996-2013, 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
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/nodes/makefuncs.c
|
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
|
|
|
|
2010-12-13 12:34:26 -05:00
|
|
|
#include "catalog/pg_class.h"
|
2004-05-10 22:44:49 +00:00
|
|
|
#include "catalog/pg_type.h"
|
1996-07-09 06:22:35 +00:00
|
|
|
#include "nodes/makefuncs.h"
|
2010-08-27 20:30:08 +00:00
|
|
|
#include "nodes/nodeFuncs.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 *
|
2006-03-14 22:48:25 +00:00
|
|
|
makeA_Expr(A_Expr_Kind kind, List *name,
|
|
|
|
Node *lexpr, Node *rexpr, int location)
|
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;
|
2006-03-14 22:48:25 +00:00
|
|
|
a->location = location;
|
2002-04-16 23:08:12 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeSimpleA_Expr -
|
|
|
|
* As above, given a simple (unqualified) operator name
|
|
|
|
*/
|
|
|
|
A_Expr *
|
2011-09-11 21:54:32 +03:00
|
|
|
makeSimpleA_Expr(A_Expr_Kind kind, char *name,
|
2006-03-14 22:48:25 +00:00
|
|
|
Node *lexpr, Node *rexpr, int location)
|
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;
|
2004-05-30 23:40:41 +00:00
|
|
|
a->name = list_make1(makeString((char *) name));
|
2002-04-16 23:08:12 +00:00
|
|
|
a->lexpr = lexpr;
|
|
|
|
a->rexpr = rexpr;
|
2006-03-14 22:48:25 +00:00
|
|
|
a->location = location;
|
2002-04-16 23:08:12 +00:00
|
|
|
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,
|
2011-02-08 23:04:18 +02:00
|
|
|
Oid varcollid,
|
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;
|
2011-02-08 23:04:18 +02:00
|
|
|
var->varcollid = varcollid;
|
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
|
|
|
/*
|
2005-10-15 02:49:52 +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
|
|
|
|
2008-08-28 23:09:48 +00:00
|
|
|
/* Likewise, we just set location to "unknown" here */
|
|
|
|
var->location = -1;
|
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
return var;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 20:30:08 +00:00
|
|
|
/*
|
|
|
|
* makeVarFromTargetEntry -
|
|
|
|
* convenience function to create a same-level Var node from a
|
|
|
|
* TargetEntry
|
|
|
|
*/
|
|
|
|
Var *
|
|
|
|
makeVarFromTargetEntry(Index varno,
|
|
|
|
TargetEntry *tle)
|
|
|
|
{
|
|
|
|
return makeVar(varno,
|
|
|
|
tle->resno,
|
|
|
|
exprType((Node *) tle->expr),
|
|
|
|
exprTypmod((Node *) tle->expr),
|
2011-02-08 23:04:18 +02:00
|
|
|
exprCollation((Node *) tle->expr),
|
2010-08-27 20:30:08 +00:00
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2010-10-19 15:08:37 -04:00
|
|
|
/*
|
|
|
|
* makeWholeRowVar -
|
|
|
|
* creates a Var node representing a whole row of the specified RTE
|
|
|
|
*
|
|
|
|
* A whole-row reference is a Var with varno set to the correct range
|
|
|
|
* table entry, and varattno == 0 to signal that it references the whole
|
|
|
|
* tuple. (Use of zero here is unclean, since it could easily be confused
|
|
|
|
* with error cases, but it's not worth changing now.) The vartype indicates
|
|
|
|
* a rowtype; either a named composite type, or RECORD. This function
|
|
|
|
* encapsulates the logic for determining the correct rowtype OID to use.
|
2011-11-27 22:27:24 -05:00
|
|
|
*
|
|
|
|
* If allowScalar is true, then for the case where the RTE is a function
|
|
|
|
* returning a non-composite result type, we produce a normal Var referencing
|
|
|
|
* the function's result directly, instead of the single-column composite
|
|
|
|
* value that the whole-row notation might otherwise suggest.
|
2013-07-29 16:38:01 +01:00
|
|
|
*
|
|
|
|
* We also handle the specific case of function RTEs with ordinality,
|
|
|
|
* where the additional column has to be added. This forces the result
|
|
|
|
* to be composite and RECORD type.
|
2010-10-19 15:08:37 -04:00
|
|
|
*/
|
|
|
|
Var *
|
|
|
|
makeWholeRowVar(RangeTblEntry *rte,
|
|
|
|
Index varno,
|
2011-11-27 22:27:24 -05:00
|
|
|
Index varlevelsup,
|
|
|
|
bool allowScalar)
|
2010-10-19 15:08:37 -04:00
|
|
|
{
|
|
|
|
Var *result;
|
|
|
|
Oid toid;
|
|
|
|
|
|
|
|
switch (rte->rtekind)
|
|
|
|
{
|
|
|
|
case RTE_RELATION:
|
|
|
|
/* relation: the rowtype is a named composite type */
|
|
|
|
toid = get_rel_type_id(rte->relid);
|
|
|
|
if (!OidIsValid(toid))
|
|
|
|
elog(ERROR, "could not find type OID for relation %u",
|
|
|
|
rte->relid);
|
|
|
|
result = makeVar(varno,
|
|
|
|
InvalidAttrNumber,
|
|
|
|
toid,
|
|
|
|
-1,
|
2011-02-08 23:04:18 +02:00
|
|
|
InvalidOid,
|
2010-10-19 15:08:37 -04:00
|
|
|
varlevelsup);
|
|
|
|
break;
|
2013-07-29 16:38:01 +01:00
|
|
|
|
2010-10-19 15:08:37 -04:00
|
|
|
case RTE_FUNCTION:
|
2013-07-29 16:38:01 +01:00
|
|
|
/*
|
|
|
|
* RTE is a function with or without ordinality. We map the
|
|
|
|
* cases as follows:
|
|
|
|
*
|
|
|
|
* If ordinality is set, we return a composite var even if
|
|
|
|
* the function is a scalar. This var is always of RECORD type.
|
|
|
|
*
|
|
|
|
* If ordinality is not set but the function returns a row,
|
|
|
|
* we keep the function's return type.
|
|
|
|
*
|
|
|
|
* If the function is a scalar, we do what allowScalar requests.
|
|
|
|
*/
|
2010-10-19 15:08:37 -04:00
|
|
|
toid = exprType(rte->funcexpr);
|
2013-07-29 16:38:01 +01:00
|
|
|
|
|
|
|
if (rte->funcordinality)
|
|
|
|
{
|
|
|
|
/* ORDINALITY always produces an anonymous RECORD result */
|
|
|
|
result = makeVar(varno,
|
|
|
|
InvalidAttrNumber,
|
|
|
|
RECORDOID,
|
|
|
|
-1,
|
|
|
|
InvalidOid,
|
|
|
|
varlevelsup);
|
|
|
|
}
|
|
|
|
else if (type_is_rowtype(toid))
|
2010-10-19 15:08:37 -04:00
|
|
|
{
|
|
|
|
/* func returns composite; same as relation case */
|
|
|
|
result = makeVar(varno,
|
|
|
|
InvalidAttrNumber,
|
|
|
|
toid,
|
|
|
|
-1,
|
2011-02-08 23:04:18 +02:00
|
|
|
InvalidOid,
|
2010-10-19 15:08:37 -04:00
|
|
|
varlevelsup);
|
|
|
|
}
|
2011-11-27 22:27:24 -05:00
|
|
|
else if (allowScalar)
|
2010-10-19 15:08:37 -04:00
|
|
|
{
|
2011-11-27 22:27:24 -05:00
|
|
|
/* func returns scalar; just return its output as-is */
|
2010-10-19 15:08:37 -04:00
|
|
|
result = makeVar(varno,
|
|
|
|
1,
|
|
|
|
toid,
|
|
|
|
-1,
|
2011-11-27 22:27:24 -05:00
|
|
|
exprCollation(rte->funcexpr),
|
|
|
|
varlevelsup);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* func returns scalar, but we want a composite result */
|
|
|
|
result = makeVar(varno,
|
|
|
|
InvalidAttrNumber,
|
|
|
|
RECORDOID,
|
|
|
|
-1,
|
2011-02-08 23:04:18 +02:00
|
|
|
InvalidOid,
|
2010-10-19 15:08:37 -04:00
|
|
|
varlevelsup);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-07-29 16:38:01 +01:00
|
|
|
default:
|
2010-10-19 15:08:37 -04:00
|
|
|
/*
|
2011-11-27 22:27:24 -05:00
|
|
|
* RTE is a join, subselect, or VALUES. We represent this as a
|
|
|
|
* whole-row Var of RECORD type. (Note that in most cases the Var
|
|
|
|
* will be expanded to a RowExpr during planning, but that is not
|
|
|
|
* our concern here.)
|
2010-10-19 15:08:37 -04:00
|
|
|
*/
|
|
|
|
result = makeVar(varno,
|
|
|
|
InvalidAttrNumber,
|
|
|
|
RECORDOID,
|
|
|
|
-1,
|
2011-02-08 23:04:18 +02:00
|
|
|
InvalidOid,
|
2010-10-19 15:08:37 -04:00
|
|
|
varlevelsup);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-07-20 19:53:53 +00:00
|
|
|
/*
|
|
|
|
* makeTargetEntry -
|
2005-04-06 16:34:07 +00:00
|
|
|
* creates a TargetEntry node
|
1998-07-20 19:53:53 +00:00
|
|
|
*/
|
|
|
|
TargetEntry *
|
2005-04-06 16:34:07 +00:00
|
|
|
makeTargetEntry(Expr *expr,
|
|
|
|
AttrNumber resno,
|
|
|
|
char *resname,
|
|
|
|
bool resjunk)
|
1998-07-20 19:53:53 +00:00
|
|
|
{
|
2005-04-06 16:34:07 +00:00
|
|
|
TargetEntry *tle = makeNode(TargetEntry);
|
1998-07-20 19:53:53 +00:00
|
|
|
|
2005-04-06 16:34:07 +00:00
|
|
|
tle->expr = expr;
|
|
|
|
tle->resno = resno;
|
|
|
|
tle->resname = resname;
|
2000-04-12 17:17:23 +00:00
|
|
|
|
|
|
|
/*
|
2005-10-15 02:49:52 +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
|
2003-05-06 00:20:33 +00:00
|
|
|
* arguments reduces the chance of error.
|
1999-08-21 03:49:17 +00:00
|
|
|
*/
|
2005-04-06 16:34:07 +00:00
|
|
|
tle->ressortgroupref = 0;
|
|
|
|
tle->resorigtbl = InvalidOid;
|
|
|
|
tle->resorigcol = 0;
|
|
|
|
|
|
|
|
tle->resjunk = resjunk;
|
2000-08-08 15:43:12 +00:00
|
|
|
|
2005-04-06 16:34:07 +00:00
|
|
|
return tle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flatCopyTargetEntry -
|
|
|
|
* duplicate a TargetEntry, but don't copy substructure
|
|
|
|
*
|
|
|
|
* This is commonly used when we just want to modify the resno or substitute
|
|
|
|
* a new expression.
|
|
|
|
*/
|
|
|
|
TargetEntry *
|
|
|
|
flatCopyTargetEntry(TargetEntry *src_tle)
|
|
|
|
{
|
|
|
|
TargetEntry *tle = makeNode(TargetEntry);
|
2003-05-06 00:20:33 +00:00
|
|
|
|
2005-04-06 16:34:07 +00:00
|
|
|
Assert(IsA(src_tle, TargetEntry));
|
|
|
|
memcpy(tle, src_tle, sizeof(TargetEntry));
|
|
|
|
return tle;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
2007-06-23 22:12:52 +00:00
|
|
|
/*
|
|
|
|
* makeFromExpr -
|
|
|
|
* creates a FromExpr node
|
|
|
|
*/
|
|
|
|
FromExpr *
|
|
|
|
makeFromExpr(List *fromlist, Node *quals)
|
|
|
|
{
|
|
|
|
FromExpr *f = makeNode(FromExpr);
|
|
|
|
|
|
|
|
f->fromlist = fromlist;
|
|
|
|
f->quals = quals;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
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,
|
2007-03-17 00:11:05 +00:00
|
|
|
int32 consttypmod,
|
2011-03-25 20:10:42 -04:00
|
|
|
Oid constcollid,
|
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;
|
2007-03-17 00:11:05 +00:00
|
|
|
cnst->consttypmod = consttypmod;
|
2011-03-25 20:10:42 -04:00
|
|
|
cnst->constcollid = constcollid;
|
1997-09-07 05:04:48 +00:00
|
|
|
cnst->constlen = constlen;
|
|
|
|
cnst->constvalue = constvalue;
|
|
|
|
cnst->constisnull = constisnull;
|
|
|
|
cnst->constbyval = constbyval;
|
2008-08-28 23:09:48 +00:00
|
|
|
cnst->location = -1; /* "unknown" */
|
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 -
|
2007-09-06 17:31:58 +00:00
|
|
|
* creates a Const node representing a NULL of the specified type/typmod
|
2007-03-17 00:11:05 +00:00
|
|
|
*
|
2007-09-06 17:31:58 +00:00
|
|
|
* This is a convenience routine that just saves a lookup of the type's
|
|
|
|
* storage properties.
|
2000-11-16 22:30:52 +00:00
|
|
|
*/
|
|
|
|
Const *
|
2011-03-25 20:10:42 -04:00
|
|
|
makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
|
2000-11-16 22:30:52 +00:00
|
|
|
{
|
|
|
|
int16 typLen;
|
|
|
|
bool typByVal;
|
|
|
|
|
|
|
|
get_typlenbyval(consttype, &typLen, &typByVal);
|
|
|
|
return makeConst(consttype,
|
2007-09-06 17:31:58 +00:00
|
|
|
consttypmod,
|
2011-03-25 20:10:42 -04:00
|
|
|
constcollid,
|
2000-11-16 22:30:52 +00:00
|
|
|
(int) typLen,
|
|
|
|
(Datum) 0,
|
|
|
|
true,
|
2002-11-25 21:29:42 +00:00
|
|
|
typByVal);
|
2000-11-16 22:30:52 +00:00
|
|
|
}
|
|
|
|
|
2004-05-10 22:44:49 +00:00
|
|
|
/*
|
|
|
|
* makeBoolConst -
|
|
|
|
* creates a Const node representing a boolean value (can be NULL too)
|
|
|
|
*/
|
|
|
|
Node *
|
|
|
|
makeBoolConst(bool value, bool isnull)
|
|
|
|
{
|
|
|
|
/* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
|
2011-03-25 20:10:42 -04:00
|
|
|
return (Node *) makeConst(BOOLOID, -1, InvalidOid, 1,
|
2007-03-17 00:11:05 +00:00
|
|
|
BoolGetDatum(value), isnull, true);
|
2004-05-10 22:44:49 +00:00
|
|
|
}
|
|
|
|
|
2002-12-12 15:49:42 +00:00
|
|
|
/*
|
|
|
|
* makeBoolExpr -
|
|
|
|
* creates a BoolExpr node
|
|
|
|
*/
|
|
|
|
Expr *
|
2008-08-28 23:09:48 +00:00
|
|
|
makeBoolExpr(BoolExprType boolop, List *args, int location)
|
2002-12-12 15:49:42 +00:00
|
|
|
{
|
|
|
|
BoolExpr *b = makeNode(BoolExpr);
|
|
|
|
|
|
|
|
b->boolop = boolop;
|
|
|
|
b->args = args;
|
2008-08-28 23:09:48 +00:00
|
|
|
b->location = location;
|
2002-12-12 15:49:42 +00:00
|
|
|
|
|
|
|
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 *
|
2011-03-19 20:29:08 -04:00
|
|
|
makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid,
|
|
|
|
CoercionForm rformat)
|
2002-03-20 19:45:13 +00:00
|
|
|
{
|
|
|
|
RelabelType *r = makeNode(RelabelType);
|
|
|
|
|
|
|
|
r->arg = arg;
|
|
|
|
r->resulttype = rtype;
|
|
|
|
r->resulttypmod = rtypmod;
|
2011-03-19 20:29:08 -04:00
|
|
|
r->resultcollid = rcollid;
|
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;
|
2008-08-28 23:09:48 +00:00
|
|
|
r->location = -1;
|
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 *
|
2008-09-01 20:42:46 +00:00
|
|
|
makeRangeVar(char *schemaname, char *relname, int location)
|
2002-03-22 02:56:37 +00:00
|
|
|
{
|
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;
|
2010-12-13 12:34:26 -05:00
|
|
|
r->relpersistence = RELPERSISTENCE_PERMANENT;
|
2002-03-22 02:56:37 +00:00
|
|
|
r->alias = NULL;
|
2008-09-01 20:42:46 +00:00
|
|
|
r->location = location;
|
2002-03-22 02:56:37 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2002-03-29 19:06:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeTypeName -
|
|
|
|
* build a TypeName node for an unqualified name.
|
2006-03-14 22:48:25 +00:00
|
|
|
*
|
|
|
|
* typmod is defaulted, but can be changed later by caller.
|
2002-03-29 19:06:29 +00:00
|
|
|
*/
|
|
|
|
TypeName *
|
|
|
|
makeTypeName(char *typnam)
|
|
|
|
{
|
2006-12-30 21:21:56 +00:00
|
|
|
return makeTypeNameFromNameList(list_make1(makeString(typnam)));
|
2006-03-14 22:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeTypeNameFromNameList -
|
|
|
|
* build a TypeName node for a String list representing a qualified name.
|
|
|
|
*
|
|
|
|
* typmod is defaulted, but can be changed later by caller.
|
|
|
|
*/
|
|
|
|
TypeName *
|
|
|
|
makeTypeNameFromNameList(List *names)
|
|
|
|
{
|
|
|
|
TypeName *n = makeNode(TypeName);
|
|
|
|
|
|
|
|
n->names = names;
|
2006-12-30 21:21:56 +00:00
|
|
|
n->typmods = NIL;
|
|
|
|
n->typemod = -1;
|
2006-03-14 22:48:25 +00:00
|
|
|
n->location = -1;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeTypeNameFromOid -
|
Remove collation information from TypeName, where it does not belong.
The initial collations patch treated a COLLATE spec as part of a TypeName,
following what can only be described as brain fade on the part of the SQL
committee. It's a lot more reasonable to treat COLLATE as a syntactically
separate object, so that it can be added in only the productions where it
actually belongs, rather than needing to reject it in a boatload of places
where it doesn't belong (something the original patch mostly failed to do).
In addition this change lets us meet the spec's requirement to allow
COLLATE anywhere in the clauses of a ColumnDef, and it avoids unfriendly
behavior for constructs such as "foo::type COLLATE collation".
To do this, pull collation information out of TypeName and put it in
ColumnDef instead, thus reverting most of the collation-related changes in
parse_type.c's API. I made one additional structural change, which was to
use a ColumnDef as an intermediate node in AT_AlterColumnType AlterTableCmd
nodes. This provides enough room to get rid of the "transform" wart in
AlterTableCmd too, since the ColumnDef can carry the USING expression
easily enough.
Also fix some other minor bugs that have crept in in the same areas,
like failure to copy recently-added fields of ColumnDef in copyfuncs.c.
While at it, document the formerly secret ability to specify a collation
in ALTER TABLE ALTER COLUMN TYPE, ALTER TYPE ADD ATTRIBUTE, and
ALTER TYPE ALTER ATTRIBUTE TYPE; and correct some misstatements about
what the default collation selection will be when COLLATE is omitted.
BTW, the three-parameter form of format_type() should go away too,
since it just contributes to the confusion in this area; but I'll do
that in a separate patch.
2011-03-09 22:38:52 -05:00
|
|
|
* build a TypeName node to represent a type already known by OID/typmod.
|
2006-03-14 22:48:25 +00:00
|
|
|
*/
|
|
|
|
TypeName *
|
Remove collation information from TypeName, where it does not belong.
The initial collations patch treated a COLLATE spec as part of a TypeName,
following what can only be described as brain fade on the part of the SQL
committee. It's a lot more reasonable to treat COLLATE as a syntactically
separate object, so that it can be added in only the productions where it
actually belongs, rather than needing to reject it in a boatload of places
where it doesn't belong (something the original patch mostly failed to do).
In addition this change lets us meet the spec's requirement to allow
COLLATE anywhere in the clauses of a ColumnDef, and it avoids unfriendly
behavior for constructs such as "foo::type COLLATE collation".
To do this, pull collation information out of TypeName and put it in
ColumnDef instead, thus reverting most of the collation-related changes in
parse_type.c's API. I made one additional structural change, which was to
use a ColumnDef as an intermediate node in AT_AlterColumnType AlterTableCmd
nodes. This provides enough room to get rid of the "transform" wart in
AlterTableCmd too, since the ColumnDef can carry the USING expression
easily enough.
Also fix some other minor bugs that have crept in in the same areas,
like failure to copy recently-added fields of ColumnDef in copyfuncs.c.
While at it, document the formerly secret ability to specify a collation
in ALTER TABLE ALTER COLUMN TYPE, ALTER TYPE ADD ATTRIBUTE, and
ALTER TYPE ALTER ATTRIBUTE TYPE; and correct some misstatements about
what the default collation selection will be when COLLATE is omitted.
BTW, the three-parameter form of format_type() should go away too,
since it just contributes to the confusion in this area; but I'll do
that in a separate patch.
2011-03-09 22:38:52 -05:00
|
|
|
makeTypeNameFromOid(Oid typeOid, int32 typmod)
|
2006-03-14 22:48:25 +00:00
|
|
|
{
|
|
|
|
TypeName *n = makeNode(TypeName);
|
|
|
|
|
2009-07-16 06:33:46 +00:00
|
|
|
n->typeOid = typeOid;
|
2006-12-30 21:21:56 +00:00
|
|
|
n->typemod = typmod;
|
2006-03-14 22:48:25 +00:00
|
|
|
n->location = -1;
|
2002-03-29 19:06:29 +00:00
|
|
|
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 *
|
2011-03-19 20:29:08 -04:00
|
|
|
makeFuncExpr(Oid funcid, Oid rettype, List *args,
|
|
|
|
Oid funccollid, Oid inputcollid, CoercionForm fformat)
|
2003-07-01 19:10:53 +00:00
|
|
|
{
|
|
|
|
FuncExpr *funcexpr;
|
|
|
|
|
|
|
|
funcexpr = makeNode(FuncExpr);
|
|
|
|
funcexpr->funcid = funcid;
|
|
|
|
funcexpr->funcresulttype = rettype;
|
|
|
|
funcexpr->funcretset = false; /* only allowed case here */
|
2013-01-21 20:25:26 -05:00
|
|
|
funcexpr->funcvariadic = false; /* only allowed case here */
|
2003-07-01 19:10:53 +00:00
|
|
|
funcexpr->funcformat = fformat;
|
2011-03-19 20:29:08 -04:00
|
|
|
funcexpr->funccollid = funccollid;
|
|
|
|
funcexpr->inputcollid = inputcollid;
|
2003-07-01 19:10:53 +00:00
|
|
|
funcexpr->args = args;
|
2008-08-28 23:09:48 +00:00
|
|
|
funcexpr->location = -1;
|
2003-07-01 19:10:53 +00:00
|
|
|
|
|
|
|
return funcexpr;
|
|
|
|
}
|
2006-08-21 00:57:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeDefElem -
|
|
|
|
* build a DefElem node
|
2009-04-04 21:12:31 +00:00
|
|
|
*
|
|
|
|
* This is sufficient for the "typical" case with an unqualified option name
|
|
|
|
* and no special action.
|
2006-08-21 00:57:26 +00:00
|
|
|
*/
|
|
|
|
DefElem *
|
|
|
|
makeDefElem(char *name, Node *arg)
|
|
|
|
{
|
2006-10-04 00:30:14 +00:00
|
|
|
DefElem *res = makeNode(DefElem);
|
2006-08-21 00:57:26 +00:00
|
|
|
|
2009-04-04 21:12:31 +00:00
|
|
|
res->defnamespace = NULL;
|
2006-08-21 00:57:26 +00:00
|
|
|
res->defname = name;
|
|
|
|
res->arg = arg;
|
2009-04-04 21:12:31 +00:00
|
|
|
res->defaction = DEFELEM_UNSPEC;
|
|
|
|
|
2006-08-21 00:57:26 +00:00
|
|
|
return res;
|
|
|
|
}
|
2008-12-19 16:25:19 +00:00
|
|
|
|
|
|
|
/*
|
2009-04-04 21:12:31 +00:00
|
|
|
* makeDefElemExtended -
|
|
|
|
* build a DefElem node with all fields available to be specified
|
2008-12-19 16:25:19 +00:00
|
|
|
*/
|
2009-04-04 21:12:31 +00:00
|
|
|
DefElem *
|
2009-07-16 06:33:46 +00:00
|
|
|
makeDefElemExtended(char *nameSpace, char *name, Node *arg,
|
2009-04-04 21:12:31 +00:00
|
|
|
DefElemAction defaction)
|
2009-02-02 19:31:40 +00:00
|
|
|
{
|
2009-04-04 21:12:31 +00:00
|
|
|
DefElem *res = makeNode(DefElem);
|
2009-02-02 19:31:40 +00:00
|
|
|
|
2009-07-16 06:33:46 +00:00
|
|
|
res->defnamespace = nameSpace;
|
2009-04-04 21:12:31 +00:00
|
|
|
res->defname = name;
|
2009-02-02 19:31:40 +00:00
|
|
|
res->arg = arg;
|
2009-04-04 21:12:31 +00:00
|
|
|
res->defaction = defaction;
|
|
|
|
|
2009-02-02 19:31:40 +00:00
|
|
|
return res;
|
|
|
|
}
|
2013-07-01 14:41:33 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* makeFuncCall -
|
|
|
|
*
|
|
|
|
* Initialize a FuncCall struct with the information every caller must
|
|
|
|
* supply. Any non-default parameters have to be handled by the
|
|
|
|
* caller.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
FuncCall *
|
|
|
|
makeFuncCall(List *name, List *args, int location)
|
|
|
|
{
|
|
|
|
FuncCall *n = makeNode(FuncCall);
|
|
|
|
n->funcname = name;
|
|
|
|
n->args = args;
|
|
|
|
n->location = location;
|
|
|
|
n->agg_order = NIL;
|
2013-07-16 20:15:36 -04:00
|
|
|
n->agg_filter = NULL;
|
2013-07-01 14:41:33 -04:00
|
|
|
n->agg_star = FALSE;
|
|
|
|
n->agg_distinct = FALSE;
|
|
|
|
n->func_variadic = FALSE;
|
|
|
|
n->over = NULL;
|
|
|
|
return n;
|
|
|
|
}
|