Alphanumeric natural order sorting : need generic solution

Started by Umashanker, Srividhyaabout 13 years ago4 messagesgeneral
Jump to latest
#1Umashanker, Srividhya
srividhya.umashanker@hp.com

All,

I am looking for a generic solution to get the Alphanumeric sorting.

* The user can request for any field to be sorted.

* There is no specific format the alphanumeric string can follow. So that we can split using regex and split and sorted.

* Need an efficient way. Should not degrade performance.

I tried all possible collation example -- select * from test order by name collate "en_US";

Is there someone who has solved this problem with writing a function?

Below are more details -

Database
[cid:image001.png@01CE26FE.97F75300]

Table
[cid:image002.png@01CE26FE.97F75300]

Rows with orderby
[cid:image003.png@01CE26FE.97F75300]

I am expecting

1, bay1
2, bay2
10, bay10
11, bay11

-vidhya

Attachments:

image001.pngimage/png; name=image001.pngDownload
image002.pngimage/png; name=image002.pngDownload
image003.pngimage/png; name=image003.pngDownload
#2Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Umashanker, Srividhya (#1)
Re: Alphanumeric natural order sorting : need generic solution

Umashanker, Srividhya wrote:

I am looking for a generic solution to get the Alphanumeric sorting.

* The user can request for any field to be sorted.
* There is no specific format the alphanumeric string can follow. So that we can split using
regex and split and sorted.
* Need an efficient way. Should not degrade performance.

I tried all possible collation example -- select * from test order by name collate "en_US";

Is there someone who has solved this problem with writing a function?

Below are more details -

I am expecting

1, bay1
2, bay2
10, bay10
11, bay11

The answer is the same as on the other mailing list:

Define precisely (not only with an example) what you mean
by "alphanumeric sorting" and you are more likely to get a helpful answer.

Yours,
Laurenz Albe

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3John R Pierce
pierce@hogranch.com
In reply to: Umashanker, Srividhya (#1)
Re: Alphanumeric natural order sorting : need generic solution

On 3/22/2013 12:40 AM, Umashanker, Srividhya wrote:

Rows with orderby

I am expecting

1, bay1

2, bay2

10, bay10

11, bay11

... order by id,name;

--
john r pierce 37N 122W
somewhere on the middle of the left coast

#4Martín Marqués
martin.marques@gmail.com
In reply to: John R Pierce (#3)
Re: Alphanumeric natural order sorting : need generic solution

2013/3/22 John R Pierce <pierce@hogranch.com>

On 3/22/2013 12:40 AM, Umashanker, Srividhya wrote:

Rows with orderby

I am expecting

1, bay1

2, bay2

10, bay10

11, bay11

... order by id,name;

That would be true if the last digits of the name attribute is equal to the
id attribute (which would mean that there is redundancy).

--
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador