Re: Inconsistent behavior on select * from void_function()? - Mailing list pgsql-hackers

From Gregory Stark
Subject Re: Inconsistent behavior on select * from void_function()?
Date
Msg-id 87ps7eoyaa.fsf@stark.xeocode.com
Whole thread Raw
In response to Inconsistent behavior on select * from void_function()?  (Josh Berkus <josh@agliodbs.com>)
List pgsql-hackers
"Josh Berkus" <josh@agliodbs.com> writes:

> postgres=# select * from void_func2(19);
>  void_func2
> ------------
>
> (1 row)
>
>
> postgres=# select void_func2(19) is null;
>  ?column?
> ----------
>  f
> (1 row)
>
>
> Why is a function which returns void returning a row?   Why is that row 
> NULL if it's a SQL function and empty if it's a PLPGSQL function?

Generally you can treat functions that return a data type as if they returned
a set of rows of that data type. I get the impression this is a considered a
quirk of the implementation and not an advertised feature though: 


postgres=# create function foo() returns integer as 'select 1' language sql;
CREATE FUNCTION
postgres=# select foo();foo 
-----  1
(1 row)

postgres=# select * from foo();foo 
-----  1
(1 row)



I can't speak to the handling of IS NULL though. It is a bit curious.

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Josh Berkus
Date:
Subject: possible de-optimization of multi-column index plans in 8.3
Next
From: "Andrew Hammond"
Date:
Subject: Re: My honours project - databases using dynamically attached entity-properties