Re: A question about "table function"

From: Joe Conway <mail(at)joeconway(dot)com>
To: Yuan Lin <yuanlin(at)mail(dot)nwpu(dot)edu(dot)cn>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: A question about "table function"
Date: 2003-03-23 23:50:36
Message-ID: 3E7E484C.8090208@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yuan Lin wrote:
> CREATE TABLE foo (fooid int, foosubid int, fooname text);
>>>As I say it, foo is already a set of columns.

"setof" refers to returning multiple rows. Multiple columns is referred
to as "composite type".

> CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
> SELECT * FROM foo WHERE fooid = $1;
> ' LANGUAGE SQL;
>
>>>here return type should be "setof setof foo".

No, the documentation is correct.

> Can I rewrite the definition as follows:
>
> CREATE TYPE foo (fooid int, foosubid int, fooname text);
>
> CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
> SELECT * FROM foo WHERE fooid = $1;
> ' LANGUAGE SQL;

You can do this *if* you don't have a table by the same name. If you do,
the CREATE TYPE will fail (but you can always try it if you need to
prove it to yourself).

Joe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2003-03-23 23:55:09 Re: Function returning SETOF RECORD]
Previous Message Joe Conway 2003-03-23 23:46:35 Re: Function returning SETOF RECORD