pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tony Wasson <ajwasson@gmail.com>
To: jim@contactbda.com
Cc: Mark R. Dingee <mark.dingee@cox.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Multi-column returns from pgsql
Date: Fri, 22 Jul 2005 11:11:09 -0700
Message-ID: <6d8daee3050722111118944657@mail.gmail.com> (raw)
In-Reply-To: <20050722165558.M96628@contactbda.com>
References: <200507221149.21550.mark.dingee@cox.net>
	<20050722165558.M96628@contactbda.com>

On 7/22/05, Jim Buttafuoco <jim@contactbda.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';



view thread (4+ messages)  latest in thread

Message-ID: <6d8daee3050722111118944657@mail.gmail.com>
Permalink:  ../6d8daee3050722111118944657@mail.gmail.com/
Also on:    postgresql.org/message-id/6d8daee3050722111118944657@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ajwasson@gmail.com, jim@contactbda.com, mark.dingee@cox.net
  Subject: Re: Multi-column returns from pgsql
  In-Reply-To: <6d8daee3050722111118944657@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox