From: Marko Tiikkaja <marko@joh.to>
To: ttmigueltt@gmail.com
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #13833: Postgres ORDER BY value inside json causes “column does not exist” error
Date: Mon, 28 Dec 2015 16:50:16 +0200
Message-ID: <56814C28.9000308@joh.to> (raw)
In-Reply-To: <20151226171902.2673.54859@wrigleys.postgresql.org>
References: <20151226171902.2673.54859@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: marko@joh.to, ttmigueltt@gmail.com
Subject: Re: BUG #13833: Postgres ORDER BY value inside json causes “column does not exist” error
In-Reply-To: <56814C28.9000308@joh.to>
References: <20151226171902.2673.54859@wrigleys.postgresql.org> <56814C28.9000308@joh.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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