Hi,
BuildTupleFromCStrings() has comment "/* Call the "in" function for
each non-dropped attribute */". It then calls the in function even
when it's going to set that attribute to NULL.
1189         if (!TupleDescAttr(tupdesc, i)->attisdropped)
1190         {
1191             /* Non-dropped attributes */
1192             dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
1193                                            values[i],
1194                                            attinmeta->attioparams[i],
1195                                            attinmeta->atttypmods[i]);
1196             if (values[i] != NULL)
1197                 nulls[i] = false;
1198             else
1199                 nulls[i] = true;
1200         }

 If we are setting isnull to true i.e. it's a NULL value, dvalues
value doesn't matter but we still invoke corresponding in function,
which looks strange and the comment doesn't help. But there's code in
make_tuple_from_result_row() which does the same thing and explain why
we need to invoke in() function even on the NULL values. I thought,
the same comment applies here. Here's patch to update the comment in
BuildTupleFromCStrings().

The code in make_tuple_from_result_row() that converts an array of
values string to tuple looks quite similar to what
BuildTupleFromCStrings() is doing with a small difference that
make_tuple_from_result_row() maintains and error context to report the
attribute whose in() function caused an error. May be we could pass an
optional error context to the later and use it.

-- 
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From c8faf979d34a04099597bdbbe952ca7a936e5dbe Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.ba...@enterprisedb.com>
Date: Fri, 23 Mar 2018 14:37:46 +0530
Subject: [PATCH] Comment fix in BuildTupleFromCStrings()

Explain in what case we need to invoke in() function even when the
value string is NULL in BuildTupleFromCStrings().

Ashutosh Bapat
---
 src/backend/executor/execTuples.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index c46d65c..5089b7f 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -1183,7 +1183,10 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
 	dvalues = (Datum *) palloc(natts * sizeof(Datum));
 	nulls = (bool *) palloc(natts * sizeof(bool));
 
-	/* Call the "in" function for each non-dropped attribute */
+	/*
+	 * Call the "in" function for each non-dropped attribute, even for nulls,
+	 * to support domains.
+	 */
 	for (i = 0; i < natts; i++)
 	{
 		if (!TupleDescAttr(tupdesc, i)->attisdropped)
-- 
1.7.9.5

Reply via email to