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

From Herbert Liechti
Subject Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...
Date
Msg-id 3C74101D.1050807@thinx.ch
Whole thread Raw
In response to Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...  (Jon Lapham <lapham@extracta.com.br>)
List pgsql-general
On Wed, 20 Feb 2002, Jon Lapham wrote:

  ...
 >
 > What I would like to to return the tuples in this order:
 > A
 > B
 > C
 > ...
 > X
 > Y
 > Z
 > AA
 > AB
 > ...
 >
 > Instead of:
 > A
 > AA
 > AB
 > ...
 > B
 > BA
 > BB

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";
}

;-)))
Best regards
Herbie
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti                                  http://www.thinx.ch
ThinX networked business services    Adlergasse 5, CH-4500 Solothurn
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


pgsql-general by date:

Previous
From: Jon Lapham
Date:
Subject: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...
Next
From: Jean-Michel POURE
Date:
Subject: Re: upgrade to 7.2 & pgdumpall