Re: Sorting problem

From: "R(dot) van Twisk" <r(dot)vantwisk(at)jongert(dot)nl>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Sorting problem
Date: 2003-10-16 06:25:26
Message-ID: 001101c393ae$4a00b9e0$fd01000a@IT001
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I think what you actually want is natural sorting.

Ries

> -----Oorspronkelijk bericht-----
> Van: pgsql-sql-owner(at)postgresql(dot)org
> [mailto:pgsql-sql-owner(at)postgresql(dot)org]Namens Jean-Luc Lachance
> Verzonden: woensdag 15 oktober 2003 17:43
> Aan: George A.J
> CC: pgsql-sql(at)postgresql(dot)org
> Onderwerp: Re: [SQL] Sorting problem
>
>
> You are obviously not using C locale.
> If you can't change it for some reason, you can use:
>
> select * from accounts order by int4( trim( acno, '#'));
>
> JLL
>
> "George A.J" wrote:
> >
> > hi all,
> > i am using postgres 7.3.2 .i am converitng a mssql database to
> > postgres.
> > now i am facing a strange problem. sorting based on a
> varchar field is
> > not working
> > as expected. the non alphanumeric characters are not
> sorting based on
> > the ascii
> > value of them.
> >
> > i have the following table structure..
> >
> > create table accounts
> > (
> > AcNo varchar (10),
> > Name varchar(100),
> > balance numeric(19,4)
> > )
> >
> > when i used the query select * from accounts order by acno. the
> > result is not correct
> >
> > suppose that the acno field contains values '###1' ,'###2' ,'##10' ,
> > '#100'
> > the sort order in postgres is
> > '###1'
> > '##10'
> > '#100'
> > '###2'
> > But i want the result as follows
> > '###1'
> > '###2'
> > '##10'
> > '#100'
> >
> > that means the ascii value of # should be considered for sorting..
> > what is the problem. is it the behaviour of postgres.
> > do i need to change any configuration. i am using all default
> > configurations
> > or is it a bug...?
> > the problem actually is of < & > operators for varchar.
> >
> > in a simple comparison
> >
> > select '###2' < '##10'
> >
> > returns false but i need true.
> >
> > is there any solution exist. even if i replaced # with any non
> > alphanumeric
> > character the result is same..
> >
> > pls help
> >
> > jinu jose
> >
> >
> ----------------------------------------------------------------------
> > Do you Yahoo!?
> > The New Yahoo! Shopping - with improved product search
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2003-10-16 12:50:21 Re: SQL function to validate money input
Previous Message Wilson Fletcher 2003-10-16 03:44:35 Re: convert integer seconds to timestamp