Re: Why select * from function doesn't work when function

From: "Francisco Figueiredo Jr(dot)" <fxjrlists(at)yahoo(dot)com(dot)br>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Why select * from function doesn't work when function
Date: 2003-07-26 00:27:40
Message-ID: 3F21CAFC.8060207@yahoo.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Nigel J. Andrews wrote:

> On Thu, 24 Jul 2003, Francisco Figueiredo Jr. wrote:
>
>
>>Nigel J. Andrews wrote:
>>
>>
>>>On Tue, 22 Jul 2003, Francisco Figueiredo Jr. wrote:
>>>
>>>
>>>
>>>>>How's this for an alternative if you really don't want any rows returned:
>>>>>
>>>>>create function fincF ( ) returns setof integer as '
>>>>>begin
>>>>> delete from blah;
>>>>> return;
>>>>>end;
>>>>>' language 'plpgsql';
>>>>>
>>>>>
>>>>
>>>>This works, but what I really want is not to return any rows. I mean,
>>>>the problem is not return null, but the error I get if I select * from
>>>>voidfunction.
>>>>
>>>>I just wanted void functions behave like others when called as select *
>>>
>>>>from voidfunction So I dont have to do select voidfunction. :)
>>>
>>>
>>>But that last does exactly that. Doesn't even return a null. Give it a quick
>>>go, skip the delete statement obviously, and see. You'll get something like:
>>>
>>> ?
>>>-------
>>>
>>>(0 rows)
>>>
>>
>>
>>Uhmmm, I think I didn't make myself clear. What I mean by void function
>>wasn't a function which just doesn't return anything. What I meant is a
>>function created like this:
>>
>>create function voidfunction returns *void* as [...]
>
>
> I knew what you meant but why the insistence on the void return type? All it's
> saying is that there isn't any interpretation that can be applied to anything
> that may (or may not) be returned from it so what are you trying to gain by
> forcing the void type when you're forced into ignoring the result anyway?
>

Oh, good. I thought I was being a little confused and could be leading
to some misunderstand. :)

I was faced by this when I received a bug report on Npgsql
(http://gborg.postgresql.org/project/npgsql/bugs/bugupdate.php?554)
about functions with void result wasn't being able to execute.

The problem is that internally, to get support of returning resultsets
from function calls, I was calling all functions with select * from
function. As I could call it this way regardless the function returned
just a single value or a resultset. I wasn't aware of the void type and
as Tom Lane also said now, other pseudotypes. So, I thought it was just
the void type which had this problem, and I was asking about why it
would behave differently from other types. I thougth it could be some
missing type, and would be a easy fix. But now I see it isn't so simple :)

>
>>The problem to me is the void in the returns ;)
>>
>>If you create a function with the returns void above you'll see that if
>>you do select * from voidfunction it gives you the error I said. But it
>>works with select voidfunction.
>
>
> Well don't create the function as returning void :)
>

:)

>
>>I just wanted it to work with select * from voidfunction too. :)
>>
>
>
> I think I did most of mine as returning integer type and the value 1 (just for
> something to return).
>

Yeah, this also would work.

Thanks Nigel for all your feedback.

--
Regards,

Francisco Figueiredo Jr.

------
"My grandfather once told me that there are two
kinds of people: those
who work and those who take the credit. He told me
to try to be in the
first group; there was less competition there."
- Indira Gandhi

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-07-26 02:08:25 Re: parallel regression test failure
Previous Message Francisco Figueiredo Jr. 2003-07-26 00:18:36 Re: Why select * from function doesn't work when function