Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKGEC-0008HF-Mi for pgsql-sql@arkaria.postgresql.org; Mon, 25 Mar 2013 22:50:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UKGEB-0004Vt-9r for pgsql-sql@arkaria.postgresql.org; Mon, 25 Mar 2013 22:50:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKGE9-0004Vn-Vr for pgsql-sql@postgresql.org; Mon, 25 Mar 2013 22:50:54 +0000 Received: from isis.morrow.me.uk ([204.109.63.142]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKGE4-0003fL-Vm for pgsql-sql@postgresql.org; Mon, 25 Mar 2013 22:50:53 +0000 Received: from anubis.morrow.me.uk (host86-173-252-28.range86-173.btcentralplus.com [86.173.252.28]) (Authenticated sender: mauzo) by isis.morrow.me.uk (Postfix) with ESMTPSA id 7EBAF450B9; Mon, 25 Mar 2013 22:50:44 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.7.4 isis.morrow.me.uk 7EBAF450B9 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=morrow.me.uk; s=dkim201101; t=1364251846; bh=VT+PAxCs+cV7izo+0wa6kRvmKHOdUlueBwYggKT6TkM=; h=Date:From:To:Subject:In-Reply-To; b=hKFhKw2ldUv/fYFX3TZfCW04oAV7WhDJ4x5ntt8+RGNM/ieQKsC7mXrCLRtnzK/dR NM/PLZFPQyK5z1LgrxLrHdte7XZ/5yi7tiGYBSJ/1WJj1XucCxTOFSjUv/nPZncM4K vy67gZ6PYSmMAsEPgjuaNbG+y2su1Fk1iXZPecpk= X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.97.6 at isis.morrow.me.uk Received: by anubis.morrow.me.uk (Postfix, from userid 5001) id EF7A7AD06; Mon, 25 Mar 2013 22:50:40 +0000 (GMT) Date: Mon, 25 Mar 2013 22:50:40 +0000 From: Ben Morrow To: cruz@sygecom.com.br, pgsql-sql@postgresql.org Subject: Re: From with case Message-ID: <20130325225034.GA73919@anubis.morrow.me.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5ba0a01548c7c6540b1c693cdf7e979d@sygecom.com.br> X-Newsgroups: pgsql.sql Organization: morrow.me.uk User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.8 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Quoth cruz@sygecom.com.br (Mauricio Cruz): > > I'm working in a PL/SQL and I'd like to use the same > PL for 2 kinds of tables... > > I have "valepag" and "valerec" both tables > have the same columns, but one is for debit and the other one is for > credit, the PL will work for both cases > > with the unique diference for > the name of the table... > > So I thought to use something like this: > ... > > For rSql in select a.adiant, > a.desc_per > from case > when > cTip='P' > then valapag > else valerec > end > where cod=2 Loop > > ... > > But > it just dont work... does some one have other solution for this case ? I would use a view for this: create view vale_any as select 'P'::text "type", v.adiant, v.desc_per, v.cod from valepag v union all select 'R', v.adiant, v.desc_per, v.cod from valerec v; then for rSql in select a.adiant, a.desc_per from vale_any a where a.type = cTip and a.cod = 2 loop You need to cast the constant in the view definition, otherwise Pg complains about its type being ambiguous. You should use the same type as cTip will be. Ben -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql