Thread: SETOF

SETOF

From
Fernando
Date:
Hi,
I am using Postgresql version 7.2.2
I made a small function...

CREATE FUNCTION ejem1(varchar) RETURNS SETOF to varchar as'
SELECT names from mi_tabla WHERE city = $1; '
language ' SQL ';

  ejem1
------------
  Sergio
  Carlos
  Fernando

When wanting to obtain several columns I do this...

CREATE FUNCTION ejem2(varchar) RETURNS SETOF mi_tabla as'
SELECT * from mi_tabla WHERE city = $1;'
language ' SQL ';

  ejem2
---------------
  137956448
  137956448
  137956448

The number of registries that return is the correct, the question is, because
it does not return the fields of the table, and that is what in its place
this showing to me...
Greetings and thank you very much!


Re: SETOF

From
Tom Lane
Date:
Fernando <fernando@icreativa.com.mx> writes:
> I am using Postgresql version 7.2.2

> CREATE FUNCTION ejem1(varchar) RETURNS SETOF to varchar as'
> SELECT names from mi_tabla WHERE city = $1; '
> language ' SQL ';

It's difficult to do anything very useful with functions returning sets
in 7.2.  Update to 7.3 and try something like:
    select * from ejem1('cityname');

            regards, tom lane

PS: it's not really necessary to post the same question in three
different PG lists.  Especially not one at a time.