Re: Multi-column returns from pgsql

From: Tony Wasson <ajwasson(at)gmail(dot)com>
To: jim(at)contactbda(dot)com
Cc: "Mark R(dot) Dingee" <mark(dot)dingee(at)cox(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Multi-column returns from pgsql
Date: 2005-07-22 18:11:09
Message-ID: 6d8daee3050722111118944657@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 7/22/05, Jim Buttafuoco <jim(at)contactbda(dot)com> wrote:
> Mark,
>
> Instead of RETURN NEXT rec.txt1; RETURN NEXT rec.txt2; just use RETURN NEXT rec;
>
> then your select statement would be
> select * from my_func() as (txt1 text,txt2 text);
>
> Jim

Besides a simple RETURN NEXT, you'll need to return a SETOF some
composite type. You can do something like

CREATE TYPE twotexts_t AS (txt1 TEXT, txt2 TEXT);

CREATE OR REPLACE FUNCTION my_func() returns SETOF twotexts_t AS '
DECLARE
rec record;
BEGIN
FOR rec IN SELECT txt1, txt2 FROM mytable LOOP
RETURN NEXT
END LOOP;
RETURN;
END;' language 'plpgsql';

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David Hofmann 2005-07-22 19:11:17 Tigger
Previous Message Bruno Wolff III 2005-07-22 17:30:14 Re: Convert numeric to money