Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZBwju-00019X-AK for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2015 03:06:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZBwjt-0004E6-65 for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2015 03:06:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZBwj3-0003Xs-RH for pgsql-bugs@postgresql.org; Mon, 06 Jul 2015 03:05:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZBwiw-0004Y5-Cy for pgsql-bugs@postgresql.org; Mon, 06 Jul 2015 03:05:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t6635Zet026540; Sun, 5 Jul 2015 23:05:35 -0400 From: Tom Lane To: longzou@hotmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13486: How can I sort unnest results? In-reply-to: <20150704010545.1190.24623@wrigleys.postgresql.org> References: <20150704010545.1190.24623@wrigleys.postgresql.org> Comments: In-reply-to longzou@hotmail.com message dated "Sat, 04 Jul 2015 01:05:45 -0000" Date: Sun, 05 Jul 2015 23:05:35 -0400 Message-ID: <26539.1436151935@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org longzou@hotmail.com writes: > I have a query that using the unnest function. But I don't know how to sort > the result. This isn't a bug, and the bug tool is not an appropriate way to ask usage questions. > For example: > select * from unnest(array[1,2,3,4,5,6], array[10,8,3,6,8,2], array['ab', > 'dd','','dd','st']); > The result will have three columns and those name are 'unnest'. So, if I use > unnest as the order by cause, it will raise an error: > ERROR: ORDER BY "unnest" is ambiguous. Assign distinct column aliases, for example # select * from unnest(array[1,2,3,4,5,6], array[10,8,3,6,8,2], array['ab', 'dd','','dd','st']) as u(a,b,c); a | b | c ---+----+---- 1 | 10 | ab 2 | 8 | dd 3 | 3 | 4 | 6 | dd 5 | 8 | st 6 | 2 | (6 rows) Now you can order on whichever column you want. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs