X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7104E9DCA87 for ; Tue, 20 Dec 2005 11:07:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98594-05 for ; Tue, 20 Dec 2005 11:07:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id E91CB9DCA8A for ; Tue, 20 Dec 2005 11:07:34 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBKF7dti029179; Tue, 20 Dec 2005 10:07:39 -0500 (EST) To: Michael Burke cc: pgsql-sql@postgresql.org Subject: Re: Sub-query as function argument In-reply-to: <200512200942.51624.michael@engtech.ca> References: <200512200942.51624.michael@engtech.ca> Comments: In-reply-to Michael Burke message dated "Tue, 20 Dec 2005 09:42:51 -0400" Date: Tue, 20 Dec 2005 10:07:39 -0500 Message-ID: <29178.1135091259@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.019 required=5 tests=[AWL=0.019] X-Spam-Score: 0.019 X-Spam-Level: X-Archive-Number: 200512/179 X-Sequence-Number: 23721 Michael Burke writes: > Is it possible to execute a SELECT query as an argument to a function? > SELECT my_func('Sample', NULL, SELECT MIN(year) FROM audio); You need parentheses around the sub-SELECT. SELECT my_func('Sample', NULL, (SELECT MIN(year) FROM audio)); This is generally true everywhere in expressions, not just in function arguments. Without the parens, it's often ambiguous what's subselect and what's outer query. regards, tom lane