How can I use row_to_json for a subset of columns in a row? (without
creating a new view or using a CTE?)
What I want returned:
{"email_address":"[email protected]","username":"joevandyk"}
Note that there is no "id" column in the result.
create table users (id serial primary key, email_address varchar,
username varchar);
insert into users (email_address, username) values ('[email protected]',
'joevandyk');
select row_to_json(users) from users;
{"id":1,"email_address":"[email protected]","username":"joevandyk"}
Correct, except that the "id" column is in the result.
select row_to_json(row(users.email_address, users.username)) from users;
{"f1":"[email protected]","f2":"joevandyk"}
The column names are incorrect.
--
Sent via pgsql-general mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general