Re: BUG #13486: How can I sort unnest results?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #13486: How can I sort unnest results?
Дата
Msg-id 26539.1436151935@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #13486: How can I sort unnest results?  (longzou@hotmail.com)
Список pgsql-bugs
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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Thomas Munro
Дата:
Сообщение: Re: BUG #13487: GetBufferFromRing code bug
Следующее
От: Fabien COELHO
Дата:
Сообщение: Re: BUG #12379: pgbench should hint to pgbench -i