Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ... - Mailing list pgsql-general

From Bryan White
Subject Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...
Date
Msg-id 004701c1ba59$200aa9f0$2ed260d1@bryan
Whole thread Raw
In response to Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...  (Herbert Liechti <Herbert.Liechti@thinx.ch>)
List pgsql-general
> In Perl you can do it with 3 lines of code. Consider the example
> below:
>
>
> #!/usr/bin/perl -w
> use strict;
>
> my @testset = ( 'A'..'Z' );
> push @testset, ( 'AA'..'ZZ' );
>
> for ( sort @testset ) {
>     print "DEFAULT ORDERING: $_\n";
> }
>
> for ( sort { length($a) <=> length($b)
>                           ||
>               $a         cmp $b } @testset ) {
>     print "ORDERING USER DEFINED: $_\n";
> }

This should work:
select * from mytable order by length(myfield),myfield;


pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: question on function definitions/casts
Next
From: Vivek Khera
Date:
Subject: Re: schema error upgrading from 7.1 to 7.2