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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nigel Horne <njh(at)bandsman(dot)co(dot)uk>
Cc: Adam Witney <awitney(at)sgul(dot)ac(dot)uk>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: http://www.postgresql.org/docs/8.0/static/xfunc-sql.html
Date: 2005-08-22 14:09:42
Message-ID: 15565.1124719782@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nigel Horne <njh(at)bandsman(dot)co(dot)uk> writes:
> It strikes me that there are two problems with this approach:

> 1) It stores the return values in the database, that seems a waste
> 2) It's slightly more complicated in that I have to delete the
> return values from the previous call before inserting the return
> values from this call, making it even more complex and slow.

You've misunderstood this completely. We are not storing anything
essential in the table, we're just using its rowtype to describe the
function's composite-type result.

Personally I would have written the example using a composite type
to make this more clear:

CREATE TYPE test_func_type AS (id int, name text);

CREATE FUNCTION test_func() RETURNS SETOF test_func_type AS $$
SELECT 1, 'me' UNION ALL SELECT 2, 'you'
$$ LANGUAGE sql;

select * from test_func();
id | name
----+------
1 | me
2 | you
(2 rows)

regards, tom lane

In response to

  • Re: at 2005-08-22 09:05:50 from Nigel Horne

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2005-08-22 14:12:21 Re:
Previous Message Nigel Horne 2005-08-22 13:56:09 Re: