Re: [SQL] function return multiply rows

From: Alvaro Herrera <alvherre(at)atentus(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: j(dot)olthof(at)millipede(dot)nl, pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] function return multiply rows
Date: 2002-09-28 04:46:00
Message-ID: 20020928004600.741e3e8f.alvherre@atentus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

En Fri, 27 Sep 2002 09:44:55 -0700
Joe Conway <mail(at)joeconway(dot)com> escribió:

> Jeroen Olthof wrote:

> > vw_teams is a view but same problem when trying it on a single table
> > CREATE FUNCTION test() RETURNS SETOF vw_teams AS 'select * from vw_teams;'
> > LANGUAGE 'sql';
> >
> > SELECT test();
> >
> > results in
> >
> > test
> > -----------
> > 137789256
> > 137789256
> > (2 rows)
>
> The capability to return composite types (multi-column rows) is limited in <=
> PostgreSQL 7.2.x. What you are seeing are pointers to the rows, not the rows
> themselves.

While you are using the old versions, I believe you can retrieve the
columns by calling them by name. At least this works on 7.2:

create table vw_teams (a int, b int);
insert into vw_teams values (1, 2);
insert into vw_teams values (3, 4);
select a(test()), b(test());
a | b
---+---
1 | 2
3 | 4
(2 rows)

I suspect the function is being evaluated twice for each row. Maybe
there's a better way.

--
Alvaro Herrera (<alvherre[a]atentus.com>)
La web junta la gente porque no importa que clase de mutante sexual seas,
tienes millones de posibles parejas. Pon "buscar gente que tengan sexo con
ciervos incendiánse", y el computador dirá "especifique el tipo de ciervo"
(Jason Alexander)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Maarten.Boekhold 2002-09-28 09:53:45 Re: [JDBC] Prepared statement performance...
Previous Message Glen Baker 2002-09-28 03:42:05 Re: 7.0 -> 7.2 Migration (oops)

Browse pgsql-sql by date

  From Date Subject
Next Message Ian Barwick 2002-09-28 22:25:06 Re: Passing array to PL/SQL and looping
Previous Message Kevin Houle 2002-09-28 03:38:29 Re: Case Sensitive "WHERE" Clauses?