Pass down the correct type for null parameters

pull/933/merge
Marco Slot 2016-11-11 07:14:08 +01:00 committed by Jason Petersen
parent 809c8b7541
commit 07da985a22
3 changed files with 40 additions and 2 deletions

View File

@ -1383,12 +1383,12 @@ ExtractParametersFromParamListInfo(ParamListInfo paramListInfo, Oid **parameterT
}
/*
* If the parameter is NULL, or is not referenced / used (ptype == 0
* If the parameter is not referenced / used (ptype == 0) and
* would otherwise have errored out inside standard_planner()),
* don't pass a value to the remote side, and pass text oid to prevent
* undetermined data type errors on workers.
*/
if (parameterData->isnull || parameterData->ptype == 0)
if (parameterData->ptype == 0)
{
(*parameterValues)[parameterIndex] = NULL;
(*parameterTypes)[parameterIndex] = TEXTOID;
@ -1396,8 +1396,20 @@ ExtractParametersFromParamListInfo(ParamListInfo paramListInfo, Oid **parameterT
continue;
}
/*
* If the parameter is NULL then we preserve its type, but
* don't need to evaluate its value.
*/
if (parameterData->isnull)
{
(*parameterValues)[parameterIndex] = NULL;
continue;
}
getTypeOutputInfo(parameterData->ptype, &typeOutputFunctionId,
&variableLengthType);
(*parameterValues)[parameterIndex] = OidOutputFunctionCall(typeOutputFunctionId,
parameterData->value);
}

View File

@ -1041,6 +1041,21 @@ SELECT * FROM plpgsql_table ORDER BY key, value;
0 |
(6 rows)
-- check whether we can handle execute parameters
CREATE TABLE execute_parameter_test (key int, val date);
SELECT create_distributed_table('execute_parameter_test', 'key');
create_distributed_table
--------------------------
(1 row)
DO $$
BEGIN
EXECUTE 'INSERT INTO execute_parameter_test VALUES (3, $1)' USING date '2000-01-01';
EXECUTE 'INSERT INTO execute_parameter_test VALUES (3, $1)' USING NULL::date;
END;
$$;
DROP TABLE execute_parameter_test;
-- clean-up functions
DROP FUNCTION plpgsql_test_1();
DROP FUNCTION plpgsql_test_2();

View File

@ -497,6 +497,17 @@ SELECT non_partition_parameter_delete(62);
-- check table after deletes
SELECT * FROM plpgsql_table ORDER BY key, value;
-- check whether we can handle execute parameters
CREATE TABLE execute_parameter_test (key int, val date);
SELECT create_distributed_table('execute_parameter_test', 'key');
DO $$
BEGIN
EXECUTE 'INSERT INTO execute_parameter_test VALUES (3, $1)' USING date '2000-01-01';
EXECUTE 'INSERT INTO execute_parameter_test VALUES (3, $1)' USING NULL::date;
END;
$$;
DROP TABLE execute_parameter_test;
-- clean-up functions
DROP FUNCTION plpgsql_test_1();
DROP FUNCTION plpgsql_test_2();