Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 56D781337990 for ; Sat, 13 Nov 2010 20:06:32 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 44959-01 for ; Sun, 14 Nov 2010 00:06:25 +0000 (UTC) X-Greylist: delayed 00:18:20.666201 by SQLgrey-1.7.6 Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by mail.postgresql.org (Postfix) with ESMTP id 9DD311336971 for ; Sat, 13 Nov 2010 20:06:24 -0400 (AST) Received: from sam.nabble.com ([192.168.236.26]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1PHPpC-0001h5-Hi for pgsql-sql@postgresql.org; Sat, 13 Nov 2010 15:48:02 -0800 Date: Sat, 13 Nov 2010 15:48:02 -0800 (PST) From: berelith To: pgsql-sql@postgresql.org Message-ID: <1289692082542-3264047.post@n5.nabble.com> Subject: Need help with plpgsql function. MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.778 tagged_above=-5 required=5 tests=BAYES_00=-1.9, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201011/27 X-Sequence-Number: 34765 Hi, I'm creating the function on a postgres 8.2 server. I would like the function to accept half a dozen varied parameters (varchars and timestamps). The first parameter will determine which one of the 6 different select queries that function is going to run. The function will return all the rows from the chosen select statement. I've been reading the postgresql documentation in creating functions that returns rowset and I've read about plpgsql. It seems to be what I need because there is going to be conditional statements. I'm just having a hard time putting it all together, and I'm not sure about the syntax and how to return the selected rows back into OUT parameters. This is a short pseudo example: CREATE OR REPLACE FUNCTION report ( -- function arguments, type will determine which one of the 6 queries to run IN type character varying(20), IN param1 character varying(255), IN param2 timestamp, -- returned values OUT code table.code%TYPE, OUT name table.name%TYPE ) RETURNS SETOF rows { LANGUAGE PLPGSQL IF type like 'type A' THEN SELECT code, name INTO rows FROM tableA join some table ....; return rows ELSIF type like 'type B' THEN SELECT code, name INTO rows FROM tableB join someothertable ... ; return rows ELSE RETURN VOID END IF; } -- View this message in context: http://postgresql.1045698.n5.nabble.com/Need-help-with-plpgsql-function-tp3264047p3264047.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.