BUG #13486: How can I sort unnest results?
BUG #13486: How can I sort unnest results?
От:
longzou@hotmail.com
Дата:
The following bug has been logged on the website: Bug reference: 13486 Logged by: Long Zou Email address: longzou@hotmail.com PostgreSQL version: 9.4.4 Operating system: Mac OS X Description: I have a query that using the unnest function. But I don't know how to sort the result. 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.
Re: BUG #13486: How can I sort unnest results?
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
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