posgtresql json data type

2,187 views
Skip to first unread message

John

unread,
Mar 10, 2014, 3:11:38 AM3/10/14
to jooq...@googlegroups.com
Hi, 
I just started using JOOQ in one of the project, i am not able to find out a way to insert a row which has a column of postgresql's json data type. Any help on this regard? 

Thanks,
John

Lukas Eder

unread,
Mar 10, 2014, 4:49:31 AM3/10/14
to jooq...@googlegroups.com
Hi John,

The last time this was discussed on the user group, we came to the conclusion that it is not that simple to integrate PostgreSQL's JSON support in jOOQ because of the limitations in the PostgreSQL JDBC driver. I'm not up to date with this evolution, though. How would you insert your JSON data through JDBC directly?

Cheers
Lukas

Relevant discussions / issues:



--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yehoh...@gmail.com

unread,
Mar 11, 2014, 5:24:09 AM3/11/14
to jooq...@googlegroups.com, yehoh...@gmail.com
I am using the below approach to directly insert json through spring jdbc templates.

PGobject jsonObject = new PGobject();
jsonObject.setType("json");
jsonObject.setValue(new Gson().toJson(attributes));
String sql = "INSERT INTO table (id, details) values (?, ?)";
new JdbcTemplate(dataSource).update(sql, "id", jsonObject);


Thanks,
John

Lukas Eder

unread,
Mar 11, 2014, 6:49:42 AM3/11/14
to jooq...@googlegroups.com, yehoh...@gmail.com
Hi John,

Thanks, that's what I had thought. This PGobject seems to be the PostgreSQL's JDBC driver's default dump for all sorts of vendor-specific types.
I suspect the way forward for jOOQ here is to

- Introduce support for a new SQLDataType.JSON type
- Include a default, ASL 2.0 licensed JSON implementation in jOOQ (preferably one that implements javax.json)
- Allow for overriding this implementation through converters

This solution should also enable JSON storage in other databases, that do not natively support this data type.

Cheers
Lukas


--

f...@changeyourflight.com

unread,
Feb 26, 2015, 4:15:12 AM2/26/15
to jooq...@googlegroups.com, yehoh...@gmail.com
Hi Lukas.
Is there any news in this regards?
(Sorry if it was already discussed on the group)

Thanks

Lukas Eder

unread,
Feb 26, 2015, 4:17:08 AM2/26/15
to jooq...@googlegroups.com
Hello,

Thanks for your enquiry. I see that you've already discovered the relevant documentation about how to integrate PostgreSQL JSON data types into jOOQ.

Right now, this is the only example that we have in the manual. We'll be adding more examples in the near future. If you have specific questions, just ask. We'll be more than happy to help

Best Regards,
Lukas

Facundo Farias

unread,
Feb 26, 2015, 4:19:02 AM2/26/15
to jooq...@googlegroups.com
Yeah, sorry for the spam :/
I do have one more question: What about if I want to used without code generation!? Where should I register the bindings?

Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/lE0TLxXEsCY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
Feb 26, 2015, 4:25:27 AM2/26/15
to jooq...@googlegroups.com
2015-02-26 10:19 GMT+01:00 Facundo Farias <f...@changeyourflight.com>:
Yeah, sorry for the spam :/

No problem at all. It's good for future readers to find cross-links that eventually lead to the right place.
 
I do have one more question: What about if I want to used without code generation!? Where should I register the bindings?

This is a good question. I realise that we'll need some documentation about that... I have registered an issue for this:

Essentially, you can use the same API as jOOQ does, internally, to create a DataType that references a Binding:

That DataType can then be used to construct new Fields, e.g. via:

Let me know if this helps
Lukas
Reply all
Reply to author
Forward
0 new messages