pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Andreas Tille <tillea@rki.de>
To: PostgreSQL SQL <pgsql-sql@postgresql.org>
Subject: Re: Scaler forms as function arguments
Date: Wed, 26 Nov 2003 17:25:21 +0000
Message-ID: <200311261725.21975.dev@archonet.com> (raw)
In-Reply-To: <Pine.LNX.4.56.0311261255210.17774@wr-linux02.rki.ivbb.bund.de>
References: <Pine.LNX.4.56.0311261255210.17774@wr-linux02.rki.ivbb.bund.de>

On Wednesday 26 November 2003 15:40, Andreas Tille wrote:
> Hi,
>
> I want to write a function of the following type
>
>    CREATE FUNCTION test ( <scalar form type> )
>          RETURNS setof MyTable
>          AS
>          'SELECT * FROM MyTable WHERE id IN $1'
>          LANGUAGE 'SQL' ;

Not as you've done it. You could pass in text "(1,2,3)", build your query and 
use EXECUTE to execute it. Alternatively, you might be able to do it with an 
array parameter (sorry, I don't use arrays, so I can't be sure).

> I was not able to find a reference whether this is possible and if yes
> how to specify the argument type and how to call this function to hand over
> the list for the IN clause correctly.
>
> Next question.  Is there any example how to return a SETOF MyTable in
> a plpgsql function?  I tried
>
>  CREATE FUNCTION test2()
>     RETURNS setof MyTable
>     AS '
>     DECLARE
>        result   SETOF MyTable ;
>     BEGIN
>       result := (SELECT * FROM MyTable);
>       RETURN result ;
>     END; ' LANGUAGE 'plpgsql';

Read the section on plpgsql in the manuals, you return results one at a time. 
For some examples, see http://techdocs.postgresql.org/ and look for the "Set 
Returning Functions" item.
-- 
  Richard Huxton
  Archonet Ltd



view thread (8+ messages)  latest in thread

Message-ID: <200311261725.21975.dev@archonet.com>
Permalink:  ../200311261725.21975.dev@archonet.com/
Also on:    postgresql.org/message-id/200311261725.21975.dev@archonet.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: dev@archonet.com, tillea@rki.de
  Subject: Re: Scaler forms as function arguments
  In-Reply-To: <200311261725.21975.dev@archonet.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