pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: avoid the creating the type for setof
Date: Fri, 30 Dec 2011 15:48:30 +0100
Message-ID: <jdkivn$7m5$1@dough.gmane.org> (raw)
In-Reply-To: <1762087.ynHxkPSFx3@linux-12>
References: <1762087.ynHxkPSFx3@linux-12>

John Fabiani wrote on 30.12.2011 15:26:
> Hi,
> I recall somewhere I saw a simple plpgsql function that returned a table with
> more than one record that did not use a defined type or a temp table ( at
> least I think I did).  Is it possible to create such a function that will
> return more than one record and not require a record type or temp table?
>
> something like
>
> return setof record as
> return query select ...
>
> return

Sure:

create or replace function
   returns table (f1 text, f2 integer)
as
$$
    select col1, col2 from some table;
$$
language sql;

If you are using PL/pgSQL you need to use "RETURN QUERY SELECT ..." inside the function.

For more details see the examples in the manual:
http://www.postgresql.org/docs/current/static/sql-createfunction.html
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RET...

Thomas






view thread (4+ messages)  latest in thread

Message-ID: <jdkivn$7m5$1@dough.gmane.org>
Permalink:  ../jdkivn$7m5$1@dough.gmane.org/
Also on:    postgresql.org/message-id/jdkivn$7m5$1@dough.gmane.org

 · 

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: spam_eater@gmx.net
  Subject: Re: avoid the creating the type for setof
  In-Reply-To: <jdkivn$7m5$1@dough.gmane.org>

* 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