mirror of
https://github.com/postgres/postgres.git
synced 2025-11-28 11:44:57 +03:00
Apply fixes for problems with dropped columns whose types have also been
dropped. Add regression test, too.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.57 2002/09/18 21:35:21 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.57.2.1 2003/05/12 00:17:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -171,6 +171,15 @@ expand_targetlist(List *tlist, int command_type,
|
||||
* the attribute, so that it gets copied to the new tuple. But
|
||||
* generate a NULL for dropped columns (we want to drop any
|
||||
* old values).
|
||||
*
|
||||
* When generating a NULL constant for a dropped column, we label
|
||||
* it INT4 (any other guaranteed-to-exist datatype would do as
|
||||
* well). We can't label it with the dropped column's datatype
|
||||
* since that might not exist anymore. It does not really
|
||||
* matter what we claim the type is, since NULL is NULL --- its
|
||||
* representation is datatype-independent. This could perhaps
|
||||
* confuse code comparing the finished plan to the target
|
||||
* relation, however.
|
||||
*/
|
||||
Oid atttype = att_tup->atttypid;
|
||||
int32 atttypmod = att_tup->atttypmod;
|
||||
@@ -179,34 +188,57 @@ expand_targetlist(List *tlist, int command_type,
|
||||
switch (command_type)
|
||||
{
|
||||
case CMD_INSERT:
|
||||
new_expr = (Node *) makeConst(atttype,
|
||||
att_tup->attlen,
|
||||
(Datum) 0,
|
||||
true, /* isnull */
|
||||
att_tup->attbyval,
|
||||
false, /* not a set */
|
||||
false);
|
||||
if (!att_tup->attisdropped)
|
||||
new_expr = coerce_type_constraints(new_expr,
|
||||
atttype,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
/* Insert NULLs for dropped columns */
|
||||
if (att_tup->attisdropped)
|
||||
{
|
||||
new_expr = (Node *) makeConst(atttype,
|
||||
att_tup->attlen,
|
||||
(Datum) 0,
|
||||
true, /* isnull */
|
||||
true, /* isnull */
|
||||
att_tup->attbyval,
|
||||
false, /* not a set */
|
||||
false);
|
||||
new_expr = coerce_type_constraints(new_expr,
|
||||
atttype,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Insert NULL for dropped column */
|
||||
new_expr = (Node *) makeConst(INT4OID,
|
||||
sizeof(int32),
|
||||
(Datum) 0,
|
||||
true, /* isnull */
|
||||
true, /* byval */
|
||||
false, /* not a set */
|
||||
false);
|
||||
/* label resdom with INT4, too */
|
||||
atttype = INT4OID;
|
||||
atttypmod = -1;
|
||||
}
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
if (!att_tup->attisdropped)
|
||||
{
|
||||
new_expr = (Node *) makeVar(result_relation,
|
||||
attrno,
|
||||
atttype,
|
||||
atttypmod,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Insert NULL for dropped column */
|
||||
new_expr = (Node *) makeConst(INT4OID,
|
||||
sizeof(int32),
|
||||
(Datum) 0,
|
||||
true, /* isnull */
|
||||
true, /* byval */
|
||||
false, /* not a set */
|
||||
false);
|
||||
/* label resdom with INT4, too */
|
||||
atttype = INT4OID;
|
||||
atttypmod = -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "expand_targetlist: unexpected command_type");
|
||||
|
||||
Reference in New Issue
Block a user