Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...

From: "Bryan White" <bryan(at)arcamax(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...
Date: 2002-02-20 21:54:09
Message-ID: 004701c1ba59$200aa9f0$2ed260d1@bryan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2002-02-20 22:01:08 Re: question on function definitions/casts
Previous Message Bruce Momjian 2002-02-20 21:47:09 Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...