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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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-13 01:20:14
Message-ID: 22160.1173748814@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> Why is a function which returns void returning a row?

Returning a scalar result that happens to be of type VOID is an entirely
different thing from returning a set result that contains no rows.

> Why is that row
> NULL if it's a SQL function and empty if it's a PLPGSQL function?

I'd say that the SQL function is probably doing the right thing. It
appears that plpgsql has hacked this specially "for backward
compatibility":

/*
* Special hack for function returning VOID: instead of NULL, return a
* non-null VOID value. This is of dubious importance but is kept for
* backwards compatibility. Note that the only other way to get here is
* to have written "RETURN NULL" in a function returning tuple.
*/
if (estate->fn_rettype == VOIDOID)
{
estate->retval = (Datum) 0;
estate->retisnull = false;
estate->rettype = VOIDOID;
}

I haven't tested, but I think that diking out this section would make
the result be a null (still of type void).

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2007-03-13 01:20:53 Re: [COMMITTERS] pgsql: Make configuration parameters fall back to their default values
Previous Message Gregory Stark 2007-03-13 01:13:15 Re: [COMMITTERS] pgsql: Make configuration parameters fall back to their default values