Re: Cast as compound type

From: "korry" <korry(dot)douglas(at)enterprisedb(dot)com>
To: "David Fetter" <david(at)fetter(dot)org>
Cc: "PG Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Cast as compound type
Date: 2008-03-31 23:18:43
Message-ID: 47F17153.60507@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

David Fetter wrote:
> I'd like to take a whack at making set-returning functions returning
> SETOF RECORD a little more fun to use. Let's imagine that we have a
> table foo and a function returning SETOF RECORD that can return foos.
> The call might look something like:
>
> SELECT a, b, c
> FROM f(ROW OF foo)
> WHERE ...;
>
> This would make it much easier and less error-prone to use SETOF
> RECORD.
>
David, it sounds like you really want to declare the return type of the
function? In your above example, you want to say that, in this
particular invocation, function f() returns a SETOF foo's. Is that correct?

If you were to create function that returns a RECORD (not a SETOF
RECORD), you would call it like this:

SELECT * FROM f() AS (column1 type1, column2 type2, column3 type3);

In your case, I think you want to declare the return type using an
explicitly defined composite type (possibly a table row); which would
imply syntax such as:

SELECT * FROM f() AS (foo);
or
SELECT * FROM f() AS (foo.*);

So, it seems like you want the syntax to look more like:

SELECT a,b,c, FROM f() AS (SETOF foo);

Does that make sense to you? Your original syntax implied that the "ROW
OF foo" was somehow related to the function arguments.

-- Korry

--

Korry Douglas <korryd(at)enterprisedb(dot)com>
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-03-31 23:26:29 How embarrassing: optimization of a one-shot query doesn't work
Previous Message Rafael Martinez 2008-03-31 23:02:34 Guessing future postgresql features