Possible bug with row_to_json

From: Jack Christensen <jack(at)jackchristensen(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Possible bug with row_to_json
Date: 2013-08-05 22:15:27
Message-ID: 520023FF.3010802@jackchristensen.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

When using a subquery as a source for row_to_json, depending on the
order of arguments it may ignore renaming a column.

jack=# create table player(
jack(# player_id serial primary key,
jack(# name varchar not null unique
jack(# );
NOTICE: CREATE TABLE will create implicit sequence
"player_player_id_seq" for serial column "player.player_id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"player_pkey" for table "player"
NOTICE: CREATE TABLE / UNIQUE will create implicit index
"player_name_key" for table "player"
CREATE TABLE
jack=# insert into player(name) values('Jack');
INSERT 0 1
jack=# select row_to_json(t)
jack-# from (
jack(# select player_id as renamed, name
jack(# from player
jack(# order by name
jack(# ) t;
row_to_json
-------------------------------
{"player_id":1,"name":"Jack"}
(1 row)

It ignored the rename.

jack=# select row_to_json(t)
from (
select name, player_id as renamed
from player
order by name
) t;
row_to_json
-----------------------------
{"name":"Jack","renamed":1}
(1 row)

But here it didn't.

Is this a bug?

Jack Christensen

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2013-08-05 22:32:41 Re: Possible bug with row_to_json
Previous Message BladeOfLight16 2013-08-05 21:15:11 Re: Re: Postgres 9.2.4 for Windows (Vista) Dell Vostro 400, re-installation failure PLEASE CAN SOMEONE HELP!! (nearly fixed)

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2013-08-05 22:32:41 Re: Possible bug with row_to_json
Previous Message Joshua D. Drake 2013-08-05 22:10:24 Re: don't own lock of type?