Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B65E7B5DBCE for ; Sun, 16 Oct 2011 05:12:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 87975-01 for ; Sun, 16 Oct 2011 08:12:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mailout02.ims-firmen.de (mailout02.ims-firmen.de [213.174.32.97]) by mail.postgresql.org (Postfix) with ESMTP id C8A7BB5D803 for ; Sun, 16 Oct 2011 05:12:01 -0300 (ADT) Received: from mailin04.ims-firmen.de ([192.168.1.113]) by mailout02.ims-firmen.de with esmtp (envelope-from ) id 1RFLp9-00007y-HI for pgsql-sql@postgresql.org; Sun, 16 Oct 2011 10:11:59 +0200 Received: from [87.170.193.79] (helo=a-kretschmer.de) by mailin04.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1RFLp9-0003CL-BI for pgsql-sql@postgresql.org; Sun, 16 Oct 2011 10:11:59 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1RFLp8-0002Pk-4B for pgsql-sql@postgresql.org; Sun, 16 Oct 2011 10:11:58 +0200 Date: Sun, 16 Oct 2011 10:11:57 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: postgres sql help Message-ID: <20111016081157.GA8614@tux> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201110/23 X-Sequence-Number: 35907 James Bond 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°