Thread: function null composite behavior

function null composite behavior

From
Rikard Pavelic
Date:
Hi,

I'm trying to resolve an issue in production due to difference between
composite null handling in plpgsql function.

Is there some way to get plain sql behavior regarding null composites
within plpgsql?

From the example:

create type composite as (i int);
create table data (i int, c composite);
insert into data (i) values(2);

create function plain_sql(inout id int, out d data) returns record as
$$ select id, d from data d where i = id $$ language sql;

create function plpg_sql(inout id int, out d data) returns record as
$$ begin select * into d from data where i = id; end; $$ language
plpgsql;

When I run queries (and expect the same result)

select d from plain_sql(2);
select d from plpg_sql(2);

I get: "(2,)" and "(2,"()")"

I assume there is no way to get sql like result from plpgsql
function?

Regards,
Rikard

--
Rikard Pavelic
https://dsl-platform.com/
http://templater.info/