| From: | Raghavendra <raghavendra(dot)rao(at)enterprisedb(dot)com> |
|---|---|
| To: | Joe Van Dyk <joe(at)tanga(dot)com> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: row_to_json question |
| Date: | 2012-06-24 02:44:13 |
| Message-ID: | CA+h6AhhX93KMZk2eEi47hsXoeuAq+W-StM=LoJCsBKwEpgGL-A@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Also try:
https://bitbucket.org/adunstan/json_91
--Raghav
On Sun, Jun 24, 2012 at 3:45 AM, Joe Van Dyk <joe(at)tanga(dot)com> wrote:
> On Sat, Jun 23, 2012 at 3:03 PM, Joe Van Dyk <joe(at)tanga(dot)com> wrote:
> > 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":"joe(at)tanga(dot)com","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 ('joe(at)tanga(dot)com',
> > 'joevandyk');
>
> This is the best I can come up with:
>
> select row_to_json(f) from (select email_address, username from users) f;
> {"email_address":"joe(at)tanga(dot)com","username":"joevandyk"}
>
> Is there a cleaner way to do this?
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Craig Ringer | 2012-06-24 06:49:40 | Re: Error message "psql: could not connect to server: No such file or directory" |
| Previous Message | Joe Van Dyk | 2012-06-23 22:15:57 | Re: row_to_json question |