mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Support assignment to subfields of composite columns in UPDATE and INSERT.
As a side effect, cause subscripts in INSERT targetlists to do something more or less sensible; previously we evaluated such subscripts and then effectively ignored them. Another side effect is that UPDATE-ing an element or slice of an array value that is NULL now produces a non-null result, namely an array containing just the assigned-to positions.
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.284 2004/05/30 23:40:27 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.285 2004/06/09 19:08:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -844,6 +844,22 @@ _copyFieldSelect(FieldSelect *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyFieldStore
|
||||
*/
|
||||
static FieldStore *
|
||||
_copyFieldStore(FieldStore *from)
|
||||
{
|
||||
FieldStore *newnode = makeNode(FieldStore);
|
||||
|
||||
COPY_NODE_FIELD(arg);
|
||||
COPY_NODE_FIELD(newvals);
|
||||
COPY_NODE_FIELD(fieldnums);
|
||||
COPY_SCALAR_FIELD(resulttype);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyRelabelType
|
||||
*/
|
||||
@@ -1275,7 +1291,6 @@ _copyColumnRef(ColumnRef *from)
|
||||
ColumnRef *newnode = makeNode(ColumnRef);
|
||||
|
||||
COPY_NODE_FIELD(fields);
|
||||
COPY_NODE_FIELD(indirection);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -1286,8 +1301,6 @@ _copyParamRef(ParamRef *from)
|
||||
ParamRef *newnode = makeNode(ParamRef);
|
||||
|
||||
COPY_SCALAR_FIELD(number);
|
||||
COPY_NODE_FIELD(fields);
|
||||
COPY_NODE_FIELD(indirection);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -1347,13 +1360,12 @@ _copyAIndices(A_Indices *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static ExprFieldSelect *
|
||||
_copyExprFieldSelect(ExprFieldSelect *from)
|
||||
static A_Indirection *
|
||||
_copyA_Indirection(A_Indirection *from)
|
||||
{
|
||||
ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
|
||||
A_Indirection *newnode = makeNode(A_Indirection);
|
||||
|
||||
COPY_NODE_FIELD(arg);
|
||||
COPY_NODE_FIELD(fields);
|
||||
COPY_NODE_FIELD(indirection);
|
||||
|
||||
return newnode;
|
||||
@@ -2648,6 +2660,9 @@ copyObject(void *from)
|
||||
case T_FieldSelect:
|
||||
retval = _copyFieldSelect(from);
|
||||
break;
|
||||
case T_FieldStore:
|
||||
retval = _copyFieldStore(from);
|
||||
break;
|
||||
case T_RelabelType:
|
||||
retval = _copyRelabelType(from);
|
||||
break;
|
||||
@@ -2984,8 +2999,8 @@ copyObject(void *from)
|
||||
case T_A_Indices:
|
||||
retval = _copyAIndices(from);
|
||||
break;
|
||||
case T_ExprFieldSelect:
|
||||
retval = _copyExprFieldSelect(from);
|
||||
case T_A_Indirection:
|
||||
retval = _copyA_Indirection(from);
|
||||
break;
|
||||
case T_ResTarget:
|
||||
retval = _copyResTarget(from);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.223 2004/05/30 23:40:27 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.224 2004/06/09 19:08:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -350,6 +350,17 @@ _equalFieldSelect(FieldSelect *a, FieldSelect *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalFieldStore(FieldStore *a, FieldStore *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(arg);
|
||||
COMPARE_NODE_FIELD(newvals);
|
||||
COMPARE_NODE_FIELD(fieldnums);
|
||||
COMPARE_SCALAR_FIELD(resulttype);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalRelabelType(RelabelType *a, RelabelType *b)
|
||||
{
|
||||
@@ -1428,7 +1439,6 @@ static bool
|
||||
_equalColumnRef(ColumnRef *a, ColumnRef *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(fields);
|
||||
COMPARE_NODE_FIELD(indirection);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1437,8 +1447,6 @@ static bool
|
||||
_equalParamRef(ParamRef *a, ParamRef *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(number);
|
||||
COMPARE_NODE_FIELD(fields);
|
||||
COMPARE_NODE_FIELD(indirection);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1474,10 +1482,9 @@ _equalAIndices(A_Indices *a, A_Indices *b)
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
|
||||
_equalA_Indirection(A_Indirection *a, A_Indirection *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(arg);
|
||||
COMPARE_NODE_FIELD(fields);
|
||||
COMPARE_NODE_FIELD(indirection);
|
||||
|
||||
return true;
|
||||
@@ -1805,6 +1812,9 @@ equal(void *a, void *b)
|
||||
case T_FieldSelect:
|
||||
retval = _equalFieldSelect(a, b);
|
||||
break;
|
||||
case T_FieldStore:
|
||||
retval = _equalFieldStore(a, b);
|
||||
break;
|
||||
case T_RelabelType:
|
||||
retval = _equalRelabelType(a, b);
|
||||
break;
|
||||
@@ -2127,8 +2137,8 @@ equal(void *a, void *b)
|
||||
case T_A_Indices:
|
||||
retval = _equalAIndices(a, b);
|
||||
break;
|
||||
case T_ExprFieldSelect:
|
||||
retval = _equalExprFieldSelect(a, b);
|
||||
case T_A_Indirection:
|
||||
retval = _equalA_Indirection(a, b);
|
||||
break;
|
||||
case T_ResTarget:
|
||||
retval = _equalResTarget(a, b);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.238 2004/05/30 23:40:27 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.239 2004/06/09 19:08:15 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every node type that can appear in stored rules' parsetrees *must*
|
||||
@@ -745,6 +745,17 @@ _outFieldSelect(StringInfo str, FieldSelect *node)
|
||||
WRITE_INT_FIELD(resulttypmod);
|
||||
}
|
||||
|
||||
static void
|
||||
_outFieldStore(StringInfo str, FieldStore *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("FIELDSTORE");
|
||||
|
||||
WRITE_NODE_FIELD(arg);
|
||||
WRITE_NODE_FIELD(newvals);
|
||||
WRITE_NODE_FIELD(fieldnums);
|
||||
WRITE_OID_FIELD(resulttype);
|
||||
}
|
||||
|
||||
static void
|
||||
_outRelabelType(StringInfo str, RelabelType *node)
|
||||
{
|
||||
@@ -1166,8 +1177,24 @@ _outSelectStmt(StringInfo str, SelectStmt *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("SELECT");
|
||||
|
||||
/* XXX this is pretty durn incomplete */
|
||||
WRITE_NODE_FIELD(whereClause);
|
||||
WRITE_NODE_FIELD(distinctClause);
|
||||
WRITE_NODE_FIELD(into);
|
||||
WRITE_NODE_FIELD(intoColNames);
|
||||
WRITE_ENUM_FIELD(intoHasOids, ContainsOids);
|
||||
WRITE_NODE_FIELD(targetList);
|
||||
WRITE_NODE_FIELD(fromClause);
|
||||
WRITE_NODE_FIELD(whereClause);
|
||||
WRITE_NODE_FIELD(groupClause);
|
||||
WRITE_NODE_FIELD(havingClause);
|
||||
WRITE_NODE_FIELD(sortClause);
|
||||
WRITE_NODE_FIELD(limitOffset);
|
||||
WRITE_NODE_FIELD(limitCount);
|
||||
WRITE_NODE_FIELD(forUpdate);
|
||||
WRITE_ENUM_FIELD(op, SetOperation);
|
||||
WRITE_BOOL_FIELD(all);
|
||||
WRITE_NODE_FIELD(larg);
|
||||
WRITE_NODE_FIELD(rarg);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1181,6 +1208,15 @@ _outFuncCall(StringInfo str, FuncCall *node)
|
||||
WRITE_BOOL_FIELD(agg_distinct);
|
||||
}
|
||||
|
||||
static void
|
||||
_outDefElem(StringInfo str, DefElem *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("DEFELEM");
|
||||
|
||||
WRITE_STRING_FIELD(defname);
|
||||
WRITE_NODE_FIELD(arg);
|
||||
}
|
||||
|
||||
static void
|
||||
_outColumnDef(StringInfo str, ColumnDef *node)
|
||||
{
|
||||
@@ -1439,7 +1475,6 @@ _outColumnRef(StringInfo str, ColumnRef *node)
|
||||
WRITE_NODE_TYPE("COLUMNREF");
|
||||
|
||||
WRITE_NODE_FIELD(fields);
|
||||
WRITE_NODE_FIELD(indirection);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1448,29 +1483,45 @@ _outParamRef(StringInfo str, ParamRef *node)
|
||||
WRITE_NODE_TYPE("PARAMREF");
|
||||
|
||||
WRITE_INT_FIELD(number);
|
||||
WRITE_NODE_FIELD(fields);
|
||||
WRITE_NODE_FIELD(indirection);
|
||||
}
|
||||
|
||||
static void
|
||||
_outAConst(StringInfo str, A_Const *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("CONST ");
|
||||
WRITE_NODE_TYPE("A_CONST");
|
||||
|
||||
_outValue(str, &(node->val));
|
||||
WRITE_NODE_FIELD(typename);
|
||||
}
|
||||
|
||||
static void
|
||||
_outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
|
||||
_outA_Indices(StringInfo str, A_Indices *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("EXPRFIELDSELECT");
|
||||
WRITE_NODE_TYPE("A_INDICES");
|
||||
|
||||
WRITE_NODE_FIELD(lidx);
|
||||
WRITE_NODE_FIELD(uidx);
|
||||
}
|
||||
|
||||
static void
|
||||
_outA_Indirection(StringInfo str, A_Indirection *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("A_INDIRECTION");
|
||||
|
||||
WRITE_NODE_FIELD(arg);
|
||||
WRITE_NODE_FIELD(fields);
|
||||
WRITE_NODE_FIELD(indirection);
|
||||
}
|
||||
|
||||
static void
|
||||
_outResTarget(StringInfo str, ResTarget *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("RESTARGET");
|
||||
|
||||
WRITE_STRING_FIELD(name);
|
||||
WRITE_NODE_FIELD(indirection);
|
||||
WRITE_NODE_FIELD(val);
|
||||
}
|
||||
|
||||
static void
|
||||
_outConstraint(StringInfo str, Constraint *node)
|
||||
{
|
||||
@@ -1666,6 +1717,9 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_FieldSelect:
|
||||
_outFieldSelect(str, obj);
|
||||
break;
|
||||
case T_FieldStore:
|
||||
_outFieldStore(str, obj);
|
||||
break;
|
||||
case T_RelabelType:
|
||||
_outRelabelType(str, obj);
|
||||
break;
|
||||
@@ -1815,8 +1869,14 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_A_Const:
|
||||
_outAConst(str, obj);
|
||||
break;
|
||||
case T_ExprFieldSelect:
|
||||
_outExprFieldSelect(str, obj);
|
||||
case T_A_Indices:
|
||||
_outA_Indices(str, obj);
|
||||
break;
|
||||
case T_A_Indirection:
|
||||
_outA_Indirection(str, obj);
|
||||
break;
|
||||
case T_ResTarget:
|
||||
_outResTarget(str, obj);
|
||||
break;
|
||||
case T_Constraint:
|
||||
_outConstraint(str, obj);
|
||||
@@ -1827,6 +1887,9 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_FuncCall:
|
||||
_outFuncCall(str, obj);
|
||||
break;
|
||||
case T_DefElem:
|
||||
_outDefElem(str, obj);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.171 2004/05/30 23:40:27 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.172 2004/06/09 19:08:15 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Path and Plan nodes do not have any readfuncs support, because we
|
||||
@@ -543,6 +543,22 @@ _readFieldSelect(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readFieldStore
|
||||
*/
|
||||
static FieldStore *
|
||||
_readFieldStore(void)
|
||||
{
|
||||
READ_LOCALS(FieldStore);
|
||||
|
||||
READ_NODE_FIELD(arg);
|
||||
READ_NODE_FIELD(newvals);
|
||||
READ_NODE_FIELD(fieldnums);
|
||||
READ_OID_FIELD(resulttype);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readRelabelType
|
||||
*/
|
||||
@@ -814,17 +830,6 @@ _readFromExpr(void)
|
||||
* Stuff from parsenodes.h.
|
||||
*/
|
||||
|
||||
static ColumnRef *
|
||||
_readColumnRef(void)
|
||||
{
|
||||
READ_LOCALS(ColumnRef);
|
||||
|
||||
READ_NODE_FIELD(fields);
|
||||
READ_NODE_FIELD(indirection);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
static ColumnDef *
|
||||
_readColumnDef(void)
|
||||
{
|
||||
@@ -859,18 +864,6 @@ _readTypeName(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
static ExprFieldSelect *
|
||||
_readExprFieldSelect(void)
|
||||
{
|
||||
READ_LOCALS(ExprFieldSelect);
|
||||
|
||||
READ_NODE_FIELD(arg);
|
||||
READ_NODE_FIELD(fields);
|
||||
READ_NODE_FIELD(indirection);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readRangeTblEntry
|
||||
*/
|
||||
@@ -974,6 +967,8 @@ parseNodeString(void)
|
||||
return_value = _readSubLink();
|
||||
else if (MATCH("FIELDSELECT", 11))
|
||||
return_value = _readFieldSelect();
|
||||
else if (MATCH("FIELDSTORE", 10))
|
||||
return_value = _readFieldStore();
|
||||
else if (MATCH("RELABELTYPE", 11))
|
||||
return_value = _readRelabelType();
|
||||
else if (MATCH("CASE", 4))
|
||||
@@ -1008,14 +1003,10 @@ parseNodeString(void)
|
||||
return_value = _readJoinExpr();
|
||||
else if (MATCH("FROMEXPR", 8))
|
||||
return_value = _readFromExpr();
|
||||
else if (MATCH("COLUMNREF", 9))
|
||||
return_value = _readColumnRef();
|
||||
else if (MATCH("COLUMNDEF", 9))
|
||||
return_value = _readColumnDef();
|
||||
else if (MATCH("TYPENAME", 8))
|
||||
return_value = _readTypeName();
|
||||
else if (MATCH("EXPRFIELDSELECT", 15))
|
||||
return_value = _readExprFieldSelect();
|
||||
else if (MATCH("RTE", 3))
|
||||
return_value = _readRangeTblEntry();
|
||||
else if (MATCH("NOTIFY", 6))
|
||||
|
||||
Reference in New Issue
Block a user