Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...
| От | Herbert Liechti |
|---|---|
| Тема | Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ... |
| Дата | |
| Msg-id | 3C74101D.1050807@thinx.ch обсуждение исходный текст |
| Ответ на | Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ... (Jon Lapham <lapham@extracta.com.br>) |
| Список | 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 по дате отправления: