Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id E43E31337B81 for ; Sun, 14 Nov 2010 14:38:09 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 21268-01-3 for ; Sun, 14 Nov 2010 18:38:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yw0-f46.google.com (mail-yw0-f46.google.com [209.85.213.46]) by mail.postgresql.org (Postfix) with ESMTP id D009A1337B9A for ; Sun, 14 Nov 2010 14:38:02 -0400 (AST) Received: by ywc21 with SMTP id 21so1383350ywc.19 for ; Sun, 14 Nov 2010 10:38:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=3MPu/JcMeV4tlp6IDmOPMJfdZrIYXPVfIkaS1nPHRC0=; b=BER+GgDhemqmPbDLo74WQ3cRd3a+hgILZyOBHNl8dR8l1Q6FbuUkdPkVb9Y0ZI4EQo 73S1qvOaoGPvlkXsR2Y/equiz0AOlZmtV4OecC63csfNVMUD8rvVgpdUcC/qBXvMcw9K b5WROUMhadPV66W//DOV6UBt/qEsiq7/i1hjI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id; b=R7iT38lJLlyUK+/SFzvxj2Hs/NQw8gTyjTdtgpmqBf38Btg/klxN+P5bGI2sgworiC 5DIv0TqjVplPpnVD2rdM/2xy8qL84S0zVzUyIejsCo7F3UKfBttotgNx+JkGIn1Q9YO1 cYlHQAOo8yqC3WCGf5lXwOFuQWn6sKthxUX8Y= Received: by 10.91.103.1 with SMTP id f1mr6590658agm.182.1289759882461; Sun, 14 Nov 2010 10:38:02 -0800 (PST) Received: from tucker.local (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id f50sm3961018yhc.38.2010.11.14.10.38.00 (version=SSLv3 cipher=RC4-MD5); Sun, 14 Nov 2010 10:38:01 -0800 (PST) From: Adrian Klaver Reply-To: adrian.klaver@gmail.com To: pgsql-sql@postgresql.org Subject: Re: Need help with plpgsql function. Date: Sun, 14 Nov 2010 10:37:58 -0800 User-Agent: KMail/1.9.10 Cc: Pavel Stehule , berelith References: <1289692082542-3264047.post@n5.nabble.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201011141037.59231.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.892 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, UPPERCASE_50_75=0.008 X-Spam-Level: X-Archive-Number: 201011/29 X-Sequence-Number: 34767 On Saturday 13 November 2010 11:15:51 pm Pavel Stehule wrote: > > } > > Hello > > you can use a RETURN QUERY statement - some like > > CREATE OR REPLACE FUNCTION foo(IN i int, OUT a int, OUT b int) > RETURNS SETOF RECORD AS $$ > BEGIN > IF i = 1 THEN > RETURN QUERY SELECT 10,20 UNION ALL SELECT 30,40; > ELSE > RETURN QUERY SELECT 60,70 UNION ALL SELECT 80,90; > END IF; > RETURN; > END; > $$ LANGUAGE plpgsql; > > SELECT * FROM foo(1); > SELECT * FROM foo(2); > > Regards > > Pavel Stehule > FYI the OP is using 8.2 :) RETURN QUERY is 8.3+ -- Adrian Klaver adrian.klaver@gmail.com