aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/preptlist.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-08-02 18:15:10 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-08-02 18:15:10 +0000
commit38bb77a5d15aa022248488bc8c0147139ce120a9 (patch)
treed01573bceae2db61eb97421f91c6068ef8522b66 /src/backend/optimizer/prep/preptlist.c
parent5e6528adf726429463a5c1f3edf712f98d6b5f7e (diff)
downloadpostgresql-38bb77a5d15aa022248488bc8c0147139ce120a9.tar.gz
postgresql-38bb77a5d15aa022248488bc8c0147139ce120a9.zip
ALTER TABLE DROP COLUMN works. Patch by Christopher Kings-Lynne,
code review by Tom Lane. Remaining issues: functions that take or return tuple types are likely to break if one drops (or adds!) a column in the table defining the type. Need to think about what to do here. Along the way: some code review for recent COPY changes; mark system columns attnotnull = true where appropriate, per discussion a month ago.
Diffstat (limited to 'src/backend/optimizer/prep/preptlist.c')
-rw-r--r--src/backend/optimizer/prep/preptlist.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c
index 1cc9f5af489..b7c0bac12c8 100644
--- a/src/backend/optimizer/prep/preptlist.c
+++ b/src/backend/optimizer/prep/preptlist.c
@@ -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.53 2002/06/20 20:29:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.54 2002/08/02 18:15:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -165,6 +165,8 @@ expand_targetlist(List *tlist, int command_type,
*
* For UPDATE, generate a Var reference to the existing value of
* 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).
*/
Oid atttype = att_tup->atttypid;
int32 atttypmod = att_tup->atttypmod;
@@ -182,11 +184,21 @@ expand_targetlist(List *tlist, int command_type,
false);
break;
case CMD_UPDATE:
- new_expr = (Node *) makeVar(result_relation,
- attrno,
- atttype,
- atttypmod,
- 0);
+ /* Insert NULLs for dropped columns */
+ if (att_tup->attisdropped)
+ new_expr = (Node *) makeConst(atttype,
+ att_tup->attlen,
+ (Datum) 0,
+ true, /* isnull */
+ att_tup->attbyval,
+ false, /* not a set */
+ false);
+ else
+ new_expr = (Node *) makeVar(result_relation,
+ attrno,
+ atttype,
+ atttypmod,
+ 0);
break;
default:
elog(ERROR, "expand_targetlist: unexpected command_type");
@@ -210,7 +222,8 @@ expand_targetlist(List *tlist, int command_type,
* the end of the new tlist, making sure they have resnos higher than
* the last real attribute. (Note: although the rewriter already did
* such renumbering, we have to do it again here in case we are doing
- * an UPDATE in an inheritance child table with more columns.)
+ * an UPDATE in a table with dropped columns, or an inheritance child
+ * table with extra columns.)
*/
while (tlist)
{