Merge pull request #979 from citusdata/bugfix/null_parameter

Pass down the correct type for null parameters
pull/973/head
Marco Slot 2016-11-11 16:57:06 -08:00 committed by GitHub
commit 5ee6a0ee3f
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()), * would otherwise have errored out inside standard_planner()),
* don't pass a value to the remote side, and pass text oid to prevent * don't pass a value to the remote side, and pass text oid to prevent
* undetermined data type errors on workers. * undetermined data type errors on workers.
*/ */
if (parameterData->isnull || parameterData->ptype == 0) if (parameterData->ptype == 0)
{ {
(*parameterValues)[parameterIndex] = NULL; (*parameterValues)[parameterIndex] = NULL;
(*parameterTypes)[parameterIndex] = TEXTOID; (*parameterTypes)[parameterIndex] = TEXTOID;
@ -1396,8 +1396,20 @@ ExtractParametersFromParamListInfo(ParamListInfo paramListInfo, Oid **parameterT
continue; 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, getTypeOutputInfo(parameterData->ptype, &typeOutputFunctionId,
&variableLengthType); &variableLengthType);
(*parameterValues)[parameterIndex] = OidOutputFunctionCall(typeOutputFunctionId, (*parameterValues)[parameterIndex] = OidOutputFunctionCall(typeOutputFunctionId,
parameterData->value); parameterData->value);
} }

View File

@ -1041,6 +1041,21 @@ SELECT * FROM plpgsql_table ORDER BY key, value;
0 | 0 |
(6 rows) (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 -- clean-up functions
DROP FUNCTION plpgsql_test_1(); DROP FUNCTION plpgsql_test_1();
DROP FUNCTION plpgsql_test_2(); DROP FUNCTION plpgsql_test_2();

View File

@ -497,6 +497,17 @@ SELECT non_partition_parameter_delete(62);
-- check table after deletes -- check table after deletes
SELECT * FROM plpgsql_table ORDER BY key, value; 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 -- clean-up functions
DROP FUNCTION plpgsql_test_1(); DROP FUNCTION plpgsql_test_1();
DROP FUNCTION plpgsql_test_2(); DROP FUNCTION plpgsql_test_2();