You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this case, because the marshal/unmarshal code converts the type to and from a string, the value that SQLite receives is actually a string, and therefore it is stored as json, i.e. text, not as jsonb, i.e. blob. If you change the table declaration to create table foo (tag blob) strict and rerun the example, you will get the error cannot store TEXT value in BLOB column foo.tag, which indicates that the value was converted to a string and not bytes.
The example can be made to work with the strict table, and therefore with values that are really jsonb, with the following changes:
The insert uses jsonb() to convert the marshalled string to the binary type: insert into foo(tag) values(jsonb(?)).
The select tag converts the binary type to the string type: select json(tag). The same isn't needed for select tag->>'country' because the return type isn't JSON.
The update uses jsonb() on the tag: update foo set tag = jsonb(?)
Either the table should be created as create table foo (tag json) or the queries should be updated to use jsonb as above.
The text was updated successfully, but these errors were encountered:
I believe the example at _examples/json/json.go may be misleading. It declares a table as
create table foo (tag jsonb)
, but since the table isn't declared asstrict
, the type is merely advisory.In this case, because the marshal/unmarshal code converts the type to and from a
string
, the value that SQLite receives is actually a string, and therefore it is stored asjson
, i.e.text
, not asjsonb
, i.e.blob
. If you change the table declaration tocreate table foo (tag blob) strict
and rerun the example, you will get the errorcannot store TEXT value in BLOB column foo.tag
, which indicates that the value was converted to a string and not bytes.The example can be made to work with the strict table, and therefore with values that are really
jsonb
, with the following changes:jsonb()
to convert the marshalled string to the binary type:insert into foo(tag) values(jsonb(?))
.select tag
converts the binary type to the string type:select json(tag)
. The same isn't needed forselect tag->>'country'
because the return type isn't JSON.jsonb()
on the tag:update foo set tag = jsonb(?)
Either the table should be created as
create table foo (tag json)
or the queries should be updated to usejsonb
as above.The text was updated successfully, but these errors were encountered: