Subject Group by subselect
Author Svein Erling Tysvær
Aage asked me a question that I answered, but we decided to write a
test case showing something that in our opinion could be handled
differently by Firebird in an ideal world.

select r1.rdb$character_set_name ||
(select r2.rdb$relation_id from rdb$database r2
where r2.rdb$character_set_name = r1.rdb$character_set_name)
from rdb$relation_id r1
group by 1

This gives an error upon prepare about 'Invalid expression in the
select list...'. It is quite a logical error and changing the group by
clause to 'group by 1, r1.rdb$character_set_name' fixes the problem.
Ideally however, I'd say Firebird ought to have discovered that the
r1.rdb$character_set_name in the where clause of the subselect already
was part of a field in the group by clause.

Just over a year ago, Pavel Menshchikov gave an answer for something
slightly similar in this thread (albeit on a subselect that I
completely agree should give an error message):
http://groups.yahoo.com/group/firebird-support/message/55819

The relevant part of his answer was:
"FB 1.5 became more "standard-oriented". And standard says you have to
specify all non-aggregate fields or their position numbers in your
GROUP BY clause"

Is this the reason? Isn't having the field in question as a part of
the GROUP BY clause enough? If I'd joined on any other field than
r1.rdb$character_set_name I would have understood that an error had to
be given.

Set