From: | "Jim Buttafuoco" <jim(at)contactbda(dot)com> |
---|---|
To: | Tony Wasson <ajwasson(at)gmail(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-23 12:57:38 |
Message-ID: | 20050723125711.M72454@contactbda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
or just return setof RECORD (version 7.4 +)
---------- Original Message -----------
From: Tony Wasson <ajwasson(at)gmail(dot)com>
To: jim(at)contactbda(dot)com
Cc: "Mark R. Dingee" <mark(dot)dingee(at)cox(dot)net>, pgsql-sql(at)postgresql(dot)org
Sent: Fri, 22 Jul 2005 11:11:09 -0700
Subject: Re: [SQL] Multi-column returns from pgsql
> 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';
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
------- End of Original Message -------
From | Date | Subject | |
---|---|---|---|
Next Message | PFC | 2005-07-24 16:45:12 | Re: Counting Row |
Previous Message | Richard Huxton | 2005-07-23 09:46:50 | Re: Is there a type like a growable array, similar Vector at |