Re: http://www.postgresql.org/docs/8.0/static/xfunc-sql.html

From: Adam Witney <awitney(at)sgul(dot)ac(dot)uk>
To: Nigel Horne <njh(at)bandsman(dot)co(dot)uk>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: http://www.postgresql.org/docs/8.0/static/xfunc-sql.html
Date: 2005-08-19 15:41:40
Message-ID: BF2BBC44.4B1F7%awitney@sgul.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 19/8/05 4:38 pm, "Nigel Horne" <njh(at)bandsman(dot)co(dot)uk> wrote:

> On Fri, 2005-08-19 at 16:30, Adam Witney wrote:
>>> I can't work out from that how to return more than one value.
>>
>> Hi Nigel,
>>
>> Add SETOF to your function like so:
>>
>> CREATE TABLE test (id int);
>> INSERT INTO test VALUES(1);
>> INSERT INTO test VALUES(2);
>>
>> CREATE FUNCTION test_func() RETURNS SETOF integer AS '
>> SELECT id FROM test;
>> ' LANGUAGE SQL;
>
> What if one value I want to return is an integer, and another one is a
> string?

Ah you want to return a record I suppose?

CREATE TABLE test (id int, name text);
INSERT INTO test VALUES(1, 'me');
INSERT INTO test VALUES(2, 'you');

CREATE FUNCTION test_func() RETURNS SETOF record AS '
SELECT id, name FROM test;
' LANGUAGE SQL;

SELECT * FROM test_func() AS (id int, name text);

id | name
----+------
1 | me
2 | you

Cheers

Adam

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

In response to

  • Re: at 2005-08-19 15:38:20 from Nigel Horne

Responses

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2005-08-19 15:58:56 Re:
Previous Message Nigel Horne 2005-08-19 15:38:20 Re: