Skip to content

Commit fc7a2af

Browse files
committed
I discovered that TupleDescGetAttInMetadata and BuildTupleFromCStrings
don't deal well with tuples having dropped columns. The attached fixes the issue. Please apply. Joe Conway
1 parent f3db606 commit fc7a2af

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/backend/executor/execTuples.c

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.71 2003/08/08 21:41:40 momjian Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.72 2003/09/29 18:22:48 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -674,16 +674,20 @@ TupleDescGetAttInMetadata(TupleDesc tupdesc)
674674
* Gather info needed later to call the "in" function for each
675675
* attribute
676676
*/
677-
attinfuncinfo = (FmgrInfo *) palloc(natts * sizeof(FmgrInfo));
678-
attelems = (Oid *) palloc(natts * sizeof(Oid));
679-
atttypmods = (int32 *) palloc(natts * sizeof(int32));
677+
attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
678+
attelems = (Oid *) palloc0(natts * sizeof(Oid));
679+
atttypmods = (int32 *) palloc0(natts * sizeof(int32));
680680

681681
for (i = 0; i < natts; i++)
682682
{
683-
atttypeid = tupdesc->attrs[i]->atttypid;
684-
getTypeInputInfo(atttypeid, &attinfuncid, &attelems[i]);
685-
fmgr_info(attinfuncid, &attinfuncinfo[i]);
686-
atttypmods[i] = tupdesc->attrs[i]->atttypmod;
683+
/* Ignore dropped attributes */
684+
if (!tupdesc->attrs[i]->attisdropped)
685+
{
686+
atttypeid = tupdesc->attrs[i]->atttypid;
687+
getTypeInputInfo(atttypeid, &attinfuncid, &attelems[i]);
688+
fmgr_info(attinfuncid, &attinfuncinfo[i]);
689+
atttypmods[i] = tupdesc->attrs[i]->atttypmod;
690+
}
687691
}
688692
attinmeta->tupdesc = tupdesc;
689693
attinmeta->attinfuncs = attinfuncinfo;
@@ -712,22 +716,32 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
712716
dvalues = (Datum *) palloc(natts * sizeof(Datum));
713717
nulls = (char *) palloc(natts * sizeof(char));
714718

715-
/* Call the "in" function for each non-null attribute */
719+
/* Call the "in" function for each non-null, non-dropped attribute */
716720
for (i = 0; i < natts; i++)
717721
{
718-
if (values[i] != NULL)
722+
if (!tupdesc->attrs[i]->attisdropped)
719723
{
720-
attelem = attinmeta->attelems[i];
721-
atttypmod = attinmeta->atttypmods[i];
722-
723-
dvalues[i] = FunctionCall3(&attinmeta->attinfuncs[i],
724-
CStringGetDatum(values[i]),
725-
ObjectIdGetDatum(attelem),
726-
Int32GetDatum(atttypmod));
727-
nulls[i] = ' ';
724+
/* Non-dropped attributes */
725+
if (values[i] != NULL)
726+
{
727+
attelem = attinmeta->attelems[i];
728+
atttypmod = attinmeta->atttypmods[i];
729+
730+
dvalues[i] = FunctionCall3(&attinmeta->attinfuncs[i],
731+
CStringGetDatum(values[i]),
732+
ObjectIdGetDatum(attelem),
733+
Int32GetDatum(atttypmod));
734+
nulls[i] = ' ';
735+
}
736+
else
737+
{
738+
dvalues[i] = (Datum) 0;
739+
nulls[i] = 'n';
740+
}
728741
}
729742
else
730743
{
744+
/* Handle dropped attributes by setting to NULL */
731745
dvalues[i] = (Datum) 0;
732746
nulls[i] = 'n';
733747
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy