Обсуждение: Re: http://www.postgresql.org/docs/8.0/static/xfunc-sql.html

Поиск
Список
Период
Сортировка

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

От
Adam Witney
Дата:
On 22/8/05 10:19 am, "Nigel Horne" <njh@bandsman.co.uk> wrote:

> On Fri, 2005-08-19 at 17:29, Tom Lane wrote:
>> Adam Witney <awitney@sgul.ac.uk> writes:
>>> 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;
>>
>> Or better, "RETURNS SETOF test", so you don't have to describe the
>> output record type every time you call it.
>
> Seeing as there will only ever be one row in this table, do I need the
> SETOF field?

Try it and see.... I think you don't need it for a single row.

adam


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


Re:

От
Nigel Horne
Дата:
On Mon, 2005-08-22 at 10:29, Adam Witney wrote:
> On 22/8/05 10:19 am, "Nigel Horne" <njh@bandsman.co.uk> wrote:
>
> > On Fri, 2005-08-19 at 17:29, Tom Lane wrote:
> >> Adam Witney <awitney@sgul.ac.uk> writes:
> >>> 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;
> >>
> >> Or better, "RETURNS SETOF test", so you don't have to describe the
> >> output record type every time you call it.
> >
> > Seeing as there will only ever be one row in this table, do I need the
> > SETOF field?
>
> Try it and see.... I think you don't need it for a single row.

Another problem comes to mind, how can I make this multi-thread
safe? Since the return values from the function are stored in the
database I need to ensure that simultaneous calls to the function are
stored independently in the temporary table.

> adam

-Nigel