Re: Sub-query as function argument

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Burke <michael(at)engtech(dot)ca>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sub-query as function argument
Date: 2005-12-20 15:07:39
Message-ID: 29178.1135091259@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Michael Burke <michael(at)engtech(dot)ca> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jim C. Nasby 2005-12-20 21:41:24 Re: Does VACUUM reorder tables on clustered indices
Previous Message Tom Lane 2005-12-20 15:05:37 Re: Querying date_time for date only ?