pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13486: How can I sort unnest results?
2+ messages / 2 participants
[nested] [flat]

* BUG #13486: How can I sort unnest results?
@ 2015-07-04 01:05 longzou@hotmail.com
  2015-07-06 03:05 ` Re: BUG #13486: How can I sort unnest results? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: longzou@hotmail.com @ 2015-07-04 01:05 UTC (permalink / raw)
  To: pgsql-bugs

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. 




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #13486: How can I sort unnest results?
  2015-07-04 01:05 BUG #13486: How can I sort unnest results? longzou@hotmail.com
@ 2015-07-06 03:05 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2015-07-06 03:05 UTC (permalink / raw)
  To: longzou@hotmail.com; +Cc: 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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2015-07-06 03:05 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-07-04 01:05 BUG #13486: How can I sort unnest results? longzou@hotmail.com
2015-07-06 03:05 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox