Support PostgreSQL JSONB data type in JdbcEventStorageEngine
See original GitHub issueJdbcEventStorageEngine
doesn’t easily support using nonstandard data types such as PostgreSQL’s JSONB for the payload and metadata columns.
The problem is that the queries pass the output of the serializer to the JDBC driver with PreparedStatement.setObject()
, but there’s no way to communicate type information.
In the case of PostgreSQL’s JDBC driver, you can insert into a JSONB column in either of two ways. First, you can add an explicit cast to the prepared statement, e.g.,
PreparedStatement ps = conn.prepareStatement("INSERT INTO foo (bar) VALUES (?::JSONB)");
ps.setObject(1, jsonFromSerializer);
Or you can pass the value as a PGobject with type information.
PreparedStatement ps = connection.prepareStatement("INSERT INTO foo (bar) VALUES (?)");
PGobject pgObject = new PGobject();
pgObject.setType("JSONB");
pgObject.setValue(jsonFromSerializer);
ps.setObject(1, pgObject);
Either approach could be exposed as a public API by JdbcEventStorageEngine. Maybe something along the lines of one of
storageEngineBuilder
.payloadBindString("?::JSONB")
.metaDataBindString("?::JSONB")
or
private PGobject wrapInPgObject(Object data) {
PGobject pgObject = new PGobject();
pgObject.setType("JSONB");
pgObject.setValue(data);
return pgObject;
}
...
storageEngineBuilder
.payloadConverter(this::wrapInPgObject)
.metaDataConverter(this::wrapInPgObject);
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Documentation: 15: 8.14. JSON Types - PostgreSQL
The jsonb data type supports array-style subscripting expressions to extract and modify elements. Nested values can be indicated by chaining subscripting ...
Read more >No-spring JDBC data store, using jsonb postgresql datatype
Desire to use jsonb for payload column in JdbcEventStorageEngine, non-spring setup. I've setup the Jackson serializer okay, ...
Read more >How to use PostgreSQL's JSONB data type with Hibernate
PostgreSQL offers proprietary datatypes to store JSON documents which are not supported by Hibernate. But you can change that with a UserType.
Read more >Processing PostgreSQL JSON & JSONB data in Java - EDB
Starting v9.2, PostgreSQL is providing native data type support for JSON objects. Subsequent releases introduced JSONB (binary formatted ...
Read more >Querying JSON (JSONB) data types in PostgreSQL - SILOTA
Querying JSON (JSONB) data types in PostgreSQL. One of the unusual features of the PostgreSQL database is the ability to store and process...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure thing @Raido0812! This blog by my former colleague Patrick was a consequence of getting PostgreSQL’s JSONB stuff to work.
That suggestion seems like it might do the trick, yes. Obviously we’ll need to try it to make sure, but it sounds reasonable.