subselects

Started by Bruce Momjianalmost 27 years ago3 messageshackers
Jump to latest
#1Bruce Momjian
bruce@momjian.us

Bruce Momjian <maillist@candle.pha.pa.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.

Gee, I didn't know they worked inside an expression, but now looking
at the grammar, I remember seeing that they should.

Added to TODO list.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#1)
Re: subselects

Bruce Momjian <maillist@candle.pha.pa.us> writes:

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 ;-)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Added to TODO list.

Added what to the TODO list? The particular behavior complained of
is history...

regards, tom lane

#3Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#2)
Re: subselects

Bruce Momjian <maillist@candle.pha.pa.us> writes:

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 ;-)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Added to TODO list.

Added what to the TODO list? The particular behavior complained of
is history...

Oh, I thought you had already fixed this long ago, but it was now being
reported as broken. Removed from list.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026