Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id E152E4ADAAB for ; Sat, 10 Dec 2011 12:17:42 -0400 (AST) Received: from mailout01.ims-firmen.de ([213.174.32.96]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RZPcK-0004f8-AB for pgsql-sql@postgresql.org; Sat, 10 Dec 2011 16:17:41 +0000 Received: from mailin02.ims-firmen.de ([192.168.1.111]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1RZPc7-0007ef-Et for pgsql-sql@postgresql.org; Sat, 10 Dec 2011 17:17:27 +0100 Received: from [87.170.172.251] (helo=a-kretschmer.de) by mailin02.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1RZPc7-0007ol-9B for pgsql-sql@postgresql.org; Sat, 10 Dec 2011 17:17:27 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1RZPc5-0004AF-Cc for pgsql-sql@postgresql.org; Sat, 10 Dec 2011 17:17:25 +0100 Date: Sat, 10 Dec 2011 17:17:25 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: conditional FROM Message-ID: <20111210161725.GA15506@tux> References: <20111210170332479879.3df30525@klingler.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20111210170332479879.3df30525@klingler.net> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/38 X-Sequence-Number: 36099 Richard Klingler wrote: > Good day... > > I'm trying to build a query for PGSQL 9.1 where a table has two > references with only one being used depending of the type of entry.. > > For example, the table has following simplified structure: > > portid primary key > port2node index to table node > port2card index to table card > > So how can I do a conditional FROM clause in the query depending on the > column port2node and port2card? > If port2card is Null or 0 I don't want it in the FROM clause as the > query will return unneccessary duplicate > row...the same goes for port2node being Null or 0... I think, you can't do that, you have to build your query and execute that string. You should use a function to do that. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°