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 |