Search Postgresql Archives

Sorting nulls and empty strings together

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



User interface need to show nulls as empty strings.
PostgreSQL sorts nulls after all data.

create temp table test ( testcol char(10) );
insert into test values ( null);
insert into test values ( 'test');
insert into test values ( '');
select * from test order by testcol;

This confuses users who expect that all empty columns are together in sorted
data.

Select statements are generated dynamically by driver and it is not easy
to change them to generate order by coalesce( testcol,'').
If there is no other way I can change driver to generate coalesce( 
testcol,'') as order by expressions.
However I'm afraid that those order by expression cannot use regular index 
like

create index test_inx on test(testcol)

in it thus too slow for large data.

How to force PostgreSQL to sort data so that nulls and empty strings appear
together ?


Andrus. 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux