Skip to content

order by a field, which is not in select distinct list -- let Firebird raise an error at prepare time [CORE2997] #3379

Open
@firebird-automations

Description

@firebird-automations

Submitted by: Volker Rehn (vr2_s18)

CREATE TABLE TEST (
TYP INTEGER,
ATEXT VARCHAR(20),
ORD SMALLINT
);
INSERT INTO TEST (ORD, TYP, ATEXT) VALUES(3, 1, 'I63.9');
INSERT INTO TEST (ORD, TYP, ATEXT) VALUES(7, 1, 'I48.10');
INSERT INTO TEST (ORD, TYP, ATEXT) VALUES(7, 1, 'I63.9');
INSERT INTO TEST (ORD, TYP, ATEXT) VALUES(8, 0, 'E78.0');
INSERT INTO TEST (ORD, TYP, ATEXT) VALUES(8, 0, 'I10.90');
INSERT INTO TEST (ORD, TYP, ATEXT) VALUES(8, 0, 'I48.10');

select
--distinct
typ, atext
from test
order by ord, atext

*Without* distinct all is as expected, the result is ordered by "ord".
*With* distinct the field "ord" isn't and cannot be used anymore.

Firebird should raise an error *at prepare time*, since it cannot solve this task without ignoring part of the given select statement.

regards, Volker

[update vr] replaced sort by ord, removed comma - thanks Sean