Hi
 
simple query raise an error 
"Cannot use an aggregate or window function in a WHERE clause, use HAVING (for 
aggregate only) instead."
 
SELECT
 *
FROM
 RDB$RELATIONS R
WHERE
 R.RDB$SYSTEM_FLAG = 1
 AND
 (SELECT
 COUNT(DISTINCT R.RDB$RELATION_NAME)
 FROM
 RDB$RELATION_FIELDS RF
 WHERE
 RF.RDB$RELATION_NAME = R.RDB$RELATION_NAME) > 11
 
 
i spend hour to find what is going on in my real complicated query ;-)
And the reason of an error is wrong alias from parent stream in COUNT(DISTINCT 
R.RDB$RELATION_NAME)
If we change it to COUNT(DISTINCT RF.RDB$RELATION_NAME) it is working ok and as 
intended.
 
I write here, to not spam the tracker, because i do not know if this is simple 
possible to catch this situation and provide more informative error message.
Maybe message should be something like this "cannot aggregate fields from 
outside stream(relation)" or simply above message should be extended with such 
info.
 
regards,
Karol Bieniaszewski
 
 
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to