NpgsqlParameter Array of smallints is receiving 0 instead of null value from postgres
1
vote
1
answer
209
views
I got strange result with NpgsqlParameter in C++/CLI project.
NpgsqlParameter^ status = wCMD->Parameters->Add(gcnew NpgsqlParameter("param1", NpgsqlDbType::Array | NpgsqlDbType::Smallint));
status->Direction = System::Data::ParameterDirection::InputOutput;
status->Value = DBNull::Value;
status->Size = 20;
CALL MySchema.MyProcedure(:param1);
In MyProcedure, I assign a array of null and 0 to param1:
CREATE OR REPLACE PROCEDURE MySchema.MyProcedure(
INOUT param1 smallint[])
LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
param1 := array[null, 0];
raise notice 'param1: %', param1;
$BODY$;
Then I got the following strange result in C++/CLI project: NpgsqlValue with arrays of shorts is [0, 0]
Could somebody help me to explain why NpgsqlParameter received arrays of zeros instead of null and 0?
Maybe NULL in C++ is 0? Or array cannot receive NULL?
How could I receive correct returned result from postgres? Example: NpgsqlValue with arrays of shorts is [NULL, 0]
I am using npgsql 4.1.12, postgresql 14.
Thanks a lot.
Asked by Thanh Dong
(9 rep)
May 8, 2023, 11:17 AM
Last activity: May 10, 2023, 04:22 AM
Last activity: May 10, 2023, 04:22 AM