pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: postgres sql help
Date: Sun, 16 Oct 2011 10:11:57 +0200
Message-ID: <20111016081157.GA8614@tux> (raw)
In-Reply-To: <SNT102-W49402A41C6B6599F082D35A8E10@phx.gbl>
References: <SNT102-W49402A41C6B6599F082D35A8E10@phx.gbl>

James Bond <coolofall@hotmail.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". i understand they are
> stored as char so i used split_part function to separate each numbers between
> "." in a separate column. but when i try to convert those column into integer,
> i am getting an error msg saying: ERROR: invalid input syntax for type numeric:
> " "
> 
> here is my code:

test=*# select * from o;
       t
---------------
 .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.
(6 rows)

Time: 0,262 ms
test=*# select * from o order by split_part(t,'.',2)::int,
split_part(t,'.',3)::int, split_part(t,'.',4)::int;
       t
---------------
 .1.3.1
 .1.3.2.5.
 .1.4.1.7.12
 .1.4.3.109.1.
 .1.4.8.66.
 .1.4.11.14.7.
(6 rows)

Time: 0,403 ms


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°



view thread (4+ messages)  latest in thread

Message-ID: <20111016081157.GA8614@tux>
Permalink:  ../20111016081157.GA8614@tux/
Also on:    postgresql.org/message-id/20111016081157.GA8614@tux

 · 

reply

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: akretschmer@spamfence.net
  Subject: Re: postgres sql help
  In-Reply-To: <20111016081157.GA8614@tux>

* 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