Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DISTINCT vs NULLS LAST clause: wrong order of NULLs [CORE1005] #1416

Closed
firebird-automations opened this issue Nov 19, 2006 · 9 comments
Closed

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @dyemanov

Is related to QA22

By Daniel Bauten:

I found a bug concerning DISTINCT and NULLS LAST. E.g. in the statement:

select DISTINCT A, B
from T
order by A, B NULLS LAST

has no affect (and the NULLs are the first results).

In particular, NULLS LAST only takes effect if the "order
by" fields are not the "prefix" (in the meaning of an
ordered set) of the "select" fields.

Another example:

select DISTINCT A, B
from T
order by A NULLS LAST --> NULLS at beginning

select DISTINCT A, B
from T
order by B NULLS LAST --> NULLS at end ==> OK

An extra note by myself: the bug exists in FB 1.5 as well just shows itself a bit differently. For example, I see wrong nulls ordering for DISTINCT and NULLS FIRST.

Commits: 484bbf0 e95f814

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @pcisar

According to my tests, this issue was not fixed in 2.0.1

create table T (A int, B int) ;
commit ;

insert into T values (1,1);
insert into T values (1,1);
insert into T values (2,2);
insert into T values (3,3);
insert into T values (null,null);
insert into T values (null,null);
insert into T values (4,4);
commit ;

select distinct A, B from T order by A, B nulls last ;

A B
============ ============
<null> <null>
1 1
2 2
3 3
4 4

select distinct A, B from T order by A nulls last ;

A B
============ ============
1 1
2 2
3 3
4 4
<null> <null>

select distinct A, B from T order by B nulls last ;

A B
============ ============
1 1
2 2
3 3
4 4
<null> <null>

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

The NULLS clause belongs to a single ORDER BY element, so if you want to see nulls at the end, you should write:
select distinct A, B from T order by A nulls last, B nulls last ;

@firebird-automations
Copy link
Collaborator Author

Commented by: @pcisar

Fix verified, test added.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Link: This issue is related to QA22 [ QA22 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 11321 ] => Firebird [ 15402 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

QA Status: No test

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

QA Status: No test => Done successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment