pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #13833: Postgres ORDER BY value inside json causes “column does not exist” error
2+ messages / 2 participants
[nested] [flat]
* BUG #13833: Postgres ORDER BY value inside json causes “column does not exist” error
@ 2015-12-26 17:19 ttmigueltt@gmail.com
0 siblings, 1 reply; 2+ messages in thread
From: ttmigueltt@gmail.com @ 2015-12-26 17:19 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 13833
Logged by: Michael Milton
Email address: ttmigueltt@gmail.com
PostgreSQL version: 9.4.4
Operating system: Fedora 22
Description:
It's probably easiest to link to the StackOverflow question I posted:
http://stackoverflow.com/questions/34472961/postgres-order-by-value-inside-json-causes-column-does-n...
The summary of it is that this query throws the error "column sets does not
exist", despite the fact that it is created in the SELECT clause:
SELECT
coalesce(block.name, 'Other') as name,
json_agg(set.data) as sets
FROM
set
FULL OUTER JOIN block ON set.block_id = block.id
GROUP BY block.id
ORDER BY sets
--
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 #13833: Postgres ORDER BY value inside json causes “column does not exist” error
@ 2015-12-28 14:50 Marko Tiikkaja <marko@joh.to>
parent: ttmigueltt@gmail.com
0 siblings, 0 replies; 2+ messages in thread
From: Marko Tiikkaja @ 2015-12-28 14:50 UTC (permalink / raw)
To: ttmigueltt@gmail.com; pgsql-bugs
On 2015-12-26 19:19, ttmigueltt@gmail.com wrote:
> It's probably easiest to link to the StackOverflow question I posted:
> http://stackoverflow.com/questions/34472961/postgres-order-by-value-inside-json-causes-column-does-n...
This is not a bug. See the accepted answer and
http://www.postgresql.org/docs/9.4/static/sql-select.html#SQL-ORDERBY:
"Each expression can be the name or ordinal number of an output column
(SELECT list item), or it can be an arbitrary expression formed from
input-column values."
The important part is that if you want to order by an arbitrary
expression, you can only use input-column values in it.
> The summary of it is that this query throws the error "column sets does not
> exist", despite the fact that it is created in the SELECT clause:
>
> SELECT
> coalesce(block.name, 'Other') as name,
> json_agg(set.data) as sets
> FROM
> set
> FULL OUTER JOIN block ON set.block_id = block.id
> GROUP BY block.id
> ORDER BY sets
No, this query really doesn't, since you're ordering by exactly the
alias, not by an expression using the alias. "ORDER BY sets IS NULL",
for example, would throw an error, but that still isn't a bug, as per above.
.m
--
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-12-28 14:50 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-12-26 17:19 BUG #13833: Postgres ORDER BY value inside json causes “column does not exist” error ttmigueltt@gmail.com
2015-12-28 14:50 ` Marko Tiikkaja <marko@joh.to>
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