function null composite behavior

Started by Rikard Pavelicover 10 years ago3 messagesgeneral
Jump to latest
#1Rikard Pavelic
rikard@ngs.hr

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/

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Rikard Pavelic
rikard@ngs.hr
In reply to: Rikard Pavelic (#1)
Re: function null composite behavior

On Sun, 25 Oct 2015 22:31:03 +0100
Rikard Pavelic <rikard@ngs.hr> wrote:

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

I should try harder ;)

Managed to get it working using array and array_agg.

Regards,
Rikard

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

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3dinesh kumar
dineshkumar02@gmail.com
In reply to: Rikard Pavelic (#2)
Re: function null composite behavior

On Mon, Oct 26, 2015 at 3:34 PM, Rikard Pavelic <rikard@ngs.hr> wrote:

On Sun, 25 Oct 2015 22:31:03 +0100
Rikard Pavelic <rikard@ngs.hr> wrote:

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

I should try harder ;)

Managed to get it working using array and array_agg.

Yeah, that works.

Might be this is what
<http://manojadinesh.blogspot.in/2011/11/pipelined-in-oracle-as-well-in.html&gt;
you are looking for.

Regards,
Rikard

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

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--

Regards,
Dinesh
manojadinesh.blogspot.com