Re: [HACKERS] "op must return bool to be used with subquery"?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] "op must return bool to be used with subquery"?
Date: 1999-05-10 16:44:37
Message-ID: 7679.926354677@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us> writes:
>> Given
>> create table t1 (name text, value float8);
>>
>> this fails:
>> SELECT name, value FROM t1 as touter WHERE
>> (value/(SELECT AVG(value) FROM t1 WHERE name = touter.name)) > 0.75;
>> ERROR: parser: '/' must return 'bool' to be used with subquery

> Aren't you really saying WHERE col / (subselect). That doesn't return
> bool, so the message seems correct.

No, look again: the result of the subselect is being used as an operand
within the WHERE clause:
WHERE (value/(SUBSELECT)) > 0.75;

If the / were the toplevel operator in the WHERE then the message would
make sense, because the WHERE clause as a whole must yield boolean.
But that doesn't mean that the operator immediately above the subselect
must yield boolean.

Besides, I already fixed this ;-)

> We don't allow subselects in target lists, or inside expressions.

We don't allow 'em in target lists, I think (anyone understand why not?)
but they work fine inside expressions in WHERE or HAVING.

regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-05-10 16:46:27 Re: [GENERAL] cluster truncates table name?
Previous Message Bruce Momjian 1999-05-10 16:40:40 Re: [HACKERS] Help/advice/suggestions on query optimizer for a large table