Re: Inconsistent behavior on select * from void_function()?

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: <josh(at)agliodbs(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Inconsistent behavior on select * from void_function()?
Date: 2007-03-12 23:08:29
Message-ID: 87ps7eoyaa.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


"Josh Berkus" <josh(at)agliodbs(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Hammond 2007-03-12 23:11:04 Re: My honours project - databases using dynamically attached entity-properties
Previous Message Josh Berkus 2007-03-12 23:01:06 possible de-optimization of multi-column index plans in 8.3