Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aDZ87-0000Gw-KV for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Dec 2015 14:50:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aDZ86-0003Sq-V4 for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Dec 2015 14:50:35 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aDZ86-0003Se-5F for pgsql-bugs@postgresql.org; Mon, 28 Dec 2015 14:50:34 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aDZ82-0003eU-P0 for pgsql-bugs@postgresql.org; Mon, 28 Dec 2015 14:50:32 +0000 Received: by mail-wm0-x22b.google.com with SMTP id l126so265852124wml.0 for ; Mon, 28 Dec 2015 06:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joh-to.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=wIdjzAfgDHFZbBJ4Y463g5Qdg4K6TkF4xKGjMBYhNp4=; b=0ssEqDGnM2/QZDaDXbnFC5nx84IA0Be6HLLaHcrRY7clWullpJDLEfhIZdwAFyZqU4 HtxGMJB+824cVG2ACtpY3xhwYX7OtihSK+OO86tpUNj0T+NiyZqcFgSnSksG7kKVqZ49 7n3lECzvcMIG4Et++/qI6gx7orrNcC+ELw4fXUAwjS4bacluN73n+qKCeI6aj2Vq7RtI BkZaI74mKFTrbAqEIf84FSt8QE+kVnf0X6Y9ZvzPh6Qw/l5AUmxlR+NLxH3hP4jeQPnE edz9fqsOMQhHyiG7yQs8vk99kZutVDQXb9288bOMAzq+14ezky4mM0gbCrh7ketZeGbw allQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=wIdjzAfgDHFZbBJ4Y463g5Qdg4K6TkF4xKGjMBYhNp4=; b=RmAVI5ZQxRQlK79tcpTakgMgdAEzieFjv+dbRZPlir9TD8NN2418ptlWoBUkaoDr5L c4PjNHDQt86tuEcuGlDULv4FbCf5aIjsQJA6YxVO2o9gGGSpledBMJJehmmG/E19veEF UyMdsonw65ZA/yarPaSLuxETlxTAXgf//Z6kKi3w645p3XnS8S0RODQypFWtB4laP0jE cGfuIm391iTYBZwAs6IQBUJIO+0q3klqRf9g4xZOwL5mrj7RZEAIH4K0zjdcUqSjOovH qus+hFt/he0Ia11ee3tVEP2eWjS4Oipwqu0niX/cdqWk+WsPVQoF1tOy+ZGVSpf83bx0 FbRw== X-Gm-Message-State: ALoCoQkAMOoz9rLjl0s+4YQuohqHviDd+nM2Vd/7YyyS1q9UPxByXNZWeROLiuxhFyrw+CbFGFHfu1kLFQ8dymq0b2CVz5QyCA== X-Received: by 10.28.146.197 with SMTP id u188mr60568704wmd.78.1451314228575; Mon, 28 Dec 2015 06:50:28 -0800 (PST) Received: from [198.18.3.62] ([188.126.80.52]) by smtp.googlemail.com with ESMTPSA id z65sm8716046wmg.10.2015.12.28.06.50.23 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Dec 2015 06:50:28 -0800 (PST) Subject: =?UTF-8?Q?Re:__BUG_#13833:_Postgres_ORDER_BY_value_inside_jso?= =?UTF-8?Q?n_causes_=e2=80=9ccolumn_does_not_exist=e2=80=9d_error?= To: ttmigueltt@gmail.com, pgsql-bugs@postgresql.org References: <20151226171902.2673.54859@wrigleys.postgresql.org> From: Marko Tiikkaja Message-ID: <56814C28.9000308@joh.to> Date: Mon, 28 Dec 2015 16:50:16 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <20151226171902.2673.54859@wrigleys.postgresql.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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-not-exist-error 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