pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
jsonb
6+ messages / 4 participants
[nested] [flat]

* jsonb
@ 2017-11-14 21:32  hmidi slim <hmidi.slim2@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: hmidi slim @ 2017-11-14 21:32 UTC (permalink / raw)
  To: pgsql-general

I have a column name of type 'jsonb' on my table named product. The format
of the column:
name: {"key1": "text1", "key2": "text2"}

When I make a query to fetch data from the table I got this format:
name: '{"key1": "text1", "key2": "text2"}'

Why does postgresql returns the name such as string type and not jsonb? is
it a bug or is there something else to add?

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: jsonb
@ 2017-11-14 22:09  Merlin Moncure <mmoncure@gmail.com>
  parent: hmidi slim <hmidi.slim2@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Merlin Moncure @ 2017-11-14 22:09 UTC (permalink / raw)
  To: hmidi slim <hmidi.slim2@gmail.com>; +Cc: pgsql-general

On Tue, Nov 14, 2017 at 3:32 PM, hmidi slim <hmidi.slim2@gmail.com> wrote:
> I have a column name of type 'jsonb' on my table named product. The format
> of the column:
> name: {"key1": "text1", "key2": "text2"}
>
> When I make a query to fetch data from the table I got this format:
> name: '{"key1": "text1", "key2": "text2"}'
>
> Why does postgresql returns the name such as string type and not jsonb? is
> it a bug or is there something else to add?

not quite following.  Can you paste the query you are trying to
execute along with the results vs. expectation?  thanks

merlin


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: jsonb
@ 2017-11-14 22:30  hmidi slim <hmidi.slim2@gmail.com>
  parent: Merlin Moncure <mmoncure@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: hmidi slim @ 2017-11-14 22:30 UTC (permalink / raw)
  To: Merlin Moncure <mmoncure@gmail.com>; +Cc: pgsql-general

I'm trying to use the function to_jsonb and create the name:
to_jsonb ('{"key1":" ' || 'text1' || '","key2":" ' || 'text2' || '"}');
But after that I used Objection.js ORM to get data using the query:
Product.query().where('id',1).then(prod => {console.log(prod)})
I think that the problem maybe with the usage of to_jsonb function, maybe I
miss something. But when I fetch the data with the ORM I found that the
type was a string and not a jsonb


2017-11-14 23:09 GMT+01:00 Merlin Moncure <mmoncure@gmail.com>:

> On Tue, Nov 14, 2017 at 3:32 PM, hmidi slim <hmidi.slim2@gmail.com> wrote:
> > I have a column name of type 'jsonb' on my table named product. The
> format
> > of the column:
> > name: {"key1": "text1", "key2": "text2"}
> >
> > When I make a query to fetch data from the table I got this format:
> > name: '{"key1": "text1", "key2": "text2"}'
> >
> > Why does postgresql returns the name such as string type and not jsonb?
> is
> > it a bug or is there something else to add?
>
> not quite following.  Can you paste the query you are trying to
> execute along with the results vs. expectation?  thanks
>
> merlin
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: jsonb
@ 2017-11-14 23:06  Merlin Moncure <mmoncure@gmail.com>
  parent: hmidi slim <hmidi.slim2@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Merlin Moncure @ 2017-11-14 23:06 UTC (permalink / raw)
  To: hmidi slim <hmidi.slim2@gmail.com>; +Cc: pgsql-general

On Tue, Nov 14, 2017 at 4:30 PM, hmidi slim <hmidi.slim2@gmail.com> wrote:
> I'm trying to use the function to_jsonb and create the name:
> to_jsonb ('{"key1":" ' || 'text1' || '","key2":" ' || 'text2' || '"}');
> But after that I used Objection.js ORM to get data using the query:
> Product.query().where('id',1).then(prod => {console.log(prod)})
> I think that the problem maybe with the usage of to_jsonb function, maybe I
> miss something. But when I fetch the data with the ORM I found that the type
> was a string and not a jsonb

Still not quite following. My advice would be to:

#1) work out the SQL you want the database to be running and verify
the results are correct

#2) figure out out to get the ORM to send that SQL

If you need help figuring out that SQL the ORM is actually running,
try turning on statement logging in postgresql.conf and watching the
log.

merlin


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: jsonb
@ 2017-11-14 23:37  Johannes Graën <johannes@selfnet.de>
  0 siblings, 0 replies; 6+ messages in thread

From: Johannes Graën @ 2017-11-14 23:37 UTC (permalink / raw)
  To: hmidi slim <hmidi.slim2@gmail.com>; +Cc: pgsql-general

On 11/14/2017 11:30 PM, hmidi slim wrote:
> I'm trying to use the function to_jsonb and create the name:
> to_jsonb ('{"key1":" ' || 'text1' || '","key2":" ' || 'text2' || '"}');

This query converts a string into a JSON object that consist of that
string. I guess what you intend to accomplish is rather:

select jsonb_build_object('key1', 'text1', 'key2', 'text2');




-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: jsonb
@ 2017-11-14 23:38  John R Pierce <pierce@hogranch.com>
  parent: hmidi slim <hmidi.slim2@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: John R Pierce @ 2017-11-14 23:38 UTC (permalink / raw)
  To: pgsql-general

On 11/14/2017 2:30 PM, hmidi slim wrote:
> I'm trying to use the function to_jsonb and create the name:
> to_jsonb ('{"key1":" ' || 'text1' || '","key2":" ' || 'text2' || '"}');
> But after that I used Objection.js ORM to get data using the query:
> Product.query().where('id',1).then(prod => {console.log(prod)})
> I think that the problem maybe with the usage of to_jsonb function, 
> maybe I miss something. But when I fetch the data with the ORM I found 
> that the type was a string and not a jsonb
>

never heard of your ORM... does it even know what postgres jsonb is ?   
do you know what actual SQL query that piece of ORMism generates ?



-- 
john r pierce, recycling bits in santa cruz



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2017-11-14 23:38 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-14 21:32 jsonb hmidi slim <hmidi.slim2@gmail.com>
2017-11-14 22:09 ` Merlin Moncure <mmoncure@gmail.com>
2017-11-14 22:30   ` hmidi slim <hmidi.slim2@gmail.com>
2017-11-14 23:06     ` Merlin Moncure <mmoncure@gmail.com>
2017-11-14 23:38     ` John R Pierce <pierce@hogranch.com>
2017-11-14 23:37 Re: jsonb Johannes Graën <johannes@selfnet.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox