Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 68E3D1337990 for ; Mon, 1 Nov 2010 21:22:40 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 44509-05 for ; Tue, 2 Nov 2010 00:22:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id E664D133729E for ; Mon, 1 Nov 2010 21:22:32 -0300 (ADT) Received: (qmail invoked by alias); 02 Nov 2010 00:22:31 -0000 Received: from mue-88-130-41-138.dsl.tropolys.de (EHLO [192.168.0.113]) [88.130.41.138] by mail.gmx.net (mp072) with SMTP; 02 Nov 2010 01:22:31 +0100 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1+3XesIksW3kVp2j8OlG0l+lArQCGAWWYtoqtLqHm usxDHKc/LGlTKF Message-ID: <4CCF59F6.7050409@gmx.net> Date: Tue, 02 Nov 2010 01:23:18 +0100 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Sorting router interfaces References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/3 X-Sequence-Number: 34741 Am 01.11.2010 13:15, schrieb Brian Sherwood: > I am trying to sort router interface names. > The problem is that I am doing a text sort and need to do a numerical sort. > > > What I get instead is the following text ordering: > > GigabitEthernet1/0/1 | 1/0/1 | {1,0,1} > GigabitEthernet1/0/10 | 1/0/10 | {1,0,10} > GigabitEthernet1/0/11 | 1/0/11 | {1,0,11} > GigabitEthernet1/0/12 | 1/0/12 | {1,0,12} > GigabitEthernet1/0/13 | 1/0/13 | {1,0,13} This was the easy part. Suppose those lines above were the input table "interfaces" and the columns were called c1, c2, c3. Since c3 is allready an array you could do this: select * from interfaces order by (c3::integer[])[1], (c3::integer[])[2], (c3::integer[])[3] Records of this type > lc-5/2/0.32769 | 5/2/0.32769 | {5,2,0.32769} work with: order by (c3::float[])[1], (c3::float[])[2], (c3::float[])[3] Now you "just" need to identify those records which wont produce such nice numerical arrays. Then split the two sets up, sort them in separate selects, add a set_nr and a row_number() as row_nr. Then UNION both sets together again AND eventually do an ORDER BY set_nr, row_nr and you are allready done. OK, that would be just an idea :)