From: Tim Landscheidt <tim@tim-landscheidt.de>
To: pgsql-sql@postgresql.org
Subject: Re: postgres sql help
Date: Mon, 17 Oct 2011 20:44:21 +0000
Message-ID: <m3lisjs5zu.fsf@passepartout.tim-landscheidt.de> (raw)
References: <SNT102-W49402A41C6B6599F082D35A8E10@phx.gbl>
<86obxhtkd1.fsf@protecting.net>
Harald Fuchs <hari.fuchs@gmail.com> wrote:
>> hi, i am fairly new in postgresql, so if anyone can help me would be great
>> if i simply do:
>> select ver_no
>> from version
>> order by ver_no
>> the result will be something like this:
>> .1.3.1
>> .1.3.2.5.
>> .1.4.1.7.12
>> .1.4.11.14.7.
>> .1.4.3.109.1.
>> .1.4.8.66.
>> so as you can see first 3 lines are ok, but how to make 1.4.3.109 come
>> before 1.4.11 because the third level "3" is smaller than "11".
> The query
> SELECT ver_no
> FROM version
> ORDER BY string_to_array(ver_no, '.', '')::int[]
> should do what you want.
Really neat! :-) For pre-9.1, you have to "ORDER BY
string_to_array(TRIM('.' FROM ver_no), '.')::int[];",
though.
Tim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tim@tim-landscheidt.de
Subject: Re: postgres sql help
In-Reply-To: <m3lisjs5zu.fsf@passepartout.tim-landscheidt.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox