mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Promote row expressions to full-fledged citizens of the expression syntax,
rather than allowing them only in a few special cases as before. In particular you can now pass a ROW() construct to a function that accepts a rowtype parameter. Internal generation of RowExprs fixes a number of corner cases that used to not work very well, such as referencing the whole-row result of a JOIN or subquery. This represents a further step in the work I started a month or so back to make rowtype values into first-class citizens.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.280 2004/05/05 04:48:45 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.281 2004/05/10 22:44:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -998,6 +998,21 @@ _copyArrayExpr(ArrayExpr *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyRowExpr
|
||||
*/
|
||||
static RowExpr *
|
||||
_copyRowExpr(RowExpr *from)
|
||||
{
|
||||
RowExpr *newnode = makeNode(RowExpr);
|
||||
|
||||
COPY_NODE_FIELD(args);
|
||||
COPY_SCALAR_FIELD(row_typeid);
|
||||
COPY_SCALAR_FIELD(row_format);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyCoalesceExpr
|
||||
*/
|
||||
@@ -2674,6 +2689,9 @@ copyObject(void *from)
|
||||
case T_ArrayExpr:
|
||||
retval = _copyArrayExpr(from);
|
||||
break;
|
||||
case T_RowExpr:
|
||||
retval = _copyRowExpr(from);
|
||||
break;
|
||||
case T_CoalesceExpr:
|
||||
retval = _copyCoalesceExpr(from);
|
||||
break;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.219 2004/05/05 04:48:45 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.220 2004/05/10 22:44:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -423,6 +423,24 @@ _equalArrayExpr(ArrayExpr *a, ArrayExpr *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalRowExpr(RowExpr *a, RowExpr *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(args);
|
||||
COMPARE_SCALAR_FIELD(row_typeid);
|
||||
|
||||
/*
|
||||
* Special-case COERCE_DONTCARE, so that planner can build coercion
|
||||
* nodes that are equal() to both explicit and implicit coercions.
|
||||
*/
|
||||
if (a->row_format != b->row_format &&
|
||||
a->row_format != COERCE_DONTCARE &&
|
||||
b->row_format != COERCE_DONTCARE)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalCoalesceExpr(CoalesceExpr *a, CoalesceExpr *b)
|
||||
{
|
||||
@@ -1748,6 +1766,9 @@ equal(void *a, void *b)
|
||||
case T_ArrayExpr:
|
||||
retval = _equalArrayExpr(a, b);
|
||||
break;
|
||||
case T_RowExpr:
|
||||
retval = _equalRowExpr(a, b);
|
||||
break;
|
||||
case T_CoalesceExpr:
|
||||
retval = _equalCoalesceExpr(a, b);
|
||||
break;
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.42 2003/11/29 19:51:49 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.43 2004/05/10 22:44:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "catalog/pg_type.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
@@ -170,6 +171,17 @@ makeNullConst(Oid consttype)
|
||||
typByVal);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
return (Node *) makeConst(BOOLOID, 1, BoolGetDatum(value), isnull, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* makeBoolExpr -
|
||||
* creates a BoolExpr node
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.235 2004/05/08 21:21:18 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.236 2004/05/10 22:44:44 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every node type that can appear in stored rules' parsetrees *must*
|
||||
@@ -828,6 +828,16 @@ _outArrayExpr(StringInfo str, ArrayExpr *node)
|
||||
WRITE_BOOL_FIELD(multidims);
|
||||
}
|
||||
|
||||
static void
|
||||
_outRowExpr(StringInfo str, RowExpr *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("ROW");
|
||||
|
||||
WRITE_NODE_FIELD(args);
|
||||
WRITE_OID_FIELD(row_typeid);
|
||||
WRITE_ENUM_FIELD(row_format, CoercionForm);
|
||||
}
|
||||
|
||||
static void
|
||||
_outCoalesceExpr(StringInfo str, CoalesceExpr *node)
|
||||
{
|
||||
@@ -1719,6 +1729,9 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_ArrayExpr:
|
||||
_outArrayExpr(str, obj);
|
||||
break;
|
||||
case T_RowExpr:
|
||||
_outRowExpr(str, obj);
|
||||
break;
|
||||
case T_CoalesceExpr:
|
||||
_outCoalesceExpr(str, obj);
|
||||
break;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.168 2004/05/08 21:21:18 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.169 2004/05/10 22:44:44 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Path and Plan nodes do not have any readfuncs support, because we
|
||||
@@ -628,6 +628,21 @@ _readArrayExpr(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readRowExpr
|
||||
*/
|
||||
static RowExpr *
|
||||
_readRowExpr(void)
|
||||
{
|
||||
READ_LOCALS(RowExpr);
|
||||
|
||||
READ_NODE_FIELD(args);
|
||||
READ_OID_FIELD(row_typeid);
|
||||
READ_ENUM_FIELD(row_format, CoercionForm);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readCoalesceExpr
|
||||
*/
|
||||
@@ -978,6 +993,8 @@ parseNodeString(void)
|
||||
return_value = _readCaseTestExpr();
|
||||
else if (MATCH("ARRAY", 5))
|
||||
return_value = _readArrayExpr();
|
||||
else if (MATCH("ROW", 3))
|
||||
return_value = _readRowExpr();
|
||||
else if (MATCH("COALESCE", 8))
|
||||
return_value = _readCoalesceExpr();
|
||||
else if (MATCH("NULLIFEXPR", 10))
|
||||
|
||||
Reference in New Issue
Block a user