On Wednesday, April 24, 2019 at 1:05:34 PM UTC-7, [email protected] wrote: > > 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.*" > > It is related to that. More exactly, you can retrieve the primitives currently stored in json/jsonb as ruby primitives, but there is no object that wraps json/jsonb primitives and therefore no way of saving such an object back to the database.
> 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? > Do you have an actual need to store JSON primitives in json/jsonb types? It's not that such support is impossible to add, but it would take some additional code and nobody has said they want such support added yet. I would like at least a reasonable use case provided before I add support for it. Thanks, Jeremy -- 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.
