According to the PG docs, the following JSON primitive types can be stored 
in a JSONB column: string, number, boolean, null. 
https://www.postgresql.org/docs/9.4/datatype-json.html.

However, when using ROM + Sequel as such:

[8] pry(main)> ds.insert(title: "A test", meta: Sequel.pg_jsonb(1))

I am getting the following error:

Sequel::DatabaseError: PG::DatatypeMismatch: ERROR:  column "meta" is of type 
jsonb but expression is of type integerLINE 1: ... INTO "books" ("title", 
"meta") VALUES ('A test', 1) RETURNI...
                                                             ^HINT:  You will 
need to rewrite or cast the expression.
from 
/Users/solnic/.gem/ruby/2.6.3/gems/sequel-5.19.0/lib/sequel/adapters/postgres.rb:152:in
 `async_exec'Caused by PG::DatatypeMismatch: ERROR:  column "meta" is of type 
jsonb but expression is of type integerLINE 1: ... INTO "books" ("title", 
"meta") VALUES ('A test', 1) RETURNI...                                         
                    ^HINT:  You will need to rewrite or cast the expression.


I am wondering if this is related to:

"The pg_json extension adds support for Sequel 
<https://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel.html> to handle 
PostgreSQL's json and jsonb types. It is slightly more strict than the 
PostgreSQL json types in that the object returned should be an array or 
object (PostgreSQL's json type considers plain numbers strings, true, 
false, and null as valid). *Sequel* 
<https://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel.html>* will 
work with PostgreSQL json values that are not arrays or objects, but 
support is fairly limited and the values do not roundtrip.*"

taken from the Sequel docs: 
https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/pg_json_rb.html
.

If so, is there any other out-of-the-box Sequel support that I will be 
foregoing by choosing to store JSON primitives in a JSONB column while 
using Sequel and Postgres rather than a JSON array or JSON hash?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to