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
I'm experimenting with converting a codebase from lib/pq to pgx. There are many instances where we Scan a jsonb value into a *json.RawMessage type. With lib/pq, this works automatically, I assume because lib/pq surfaces jsonb values to database/sql as a []byte. Using pgx, I get
sql: Scan error on column index 3: unsupported Scan, storing driver.Value type string into type *json.RawMessage
seeming to indicate pgx/stdlib surfaces the jsonb value to database/sql as a string. Is string the appropriate type? Sorry if this is an uneducated question, as I'm fairly ignorant of the innards of database/sql.
It would be really convenient to be able to Scan directly into json.RawMessage types. I can always work around this by scanning into a []byte and converting to a json.RawMessage later.
The text was updated successfully, but these errors were encountered:
It's hard to say whether string or []byte is the true / better representation of PostgreSQL json text. But I was able to change it to []byte. database/sql will automatically convert []byte to string when scanning so this change enables your use case (and becomes compatible with lib/pq) without any backwards incompatibility.
I'm experimenting with converting a codebase from lib/pq to pgx. There are many instances where we Scan a jsonb value into a *json.RawMessage type. With lib/pq, this works automatically, I assume because lib/pq surfaces jsonb values to database/sql as a
[]byte
. Using pgx, I getseeming to indicate pgx/stdlib surfaces the jsonb value to database/sql as a string. Is string the appropriate type? Sorry if this is an uneducated question, as I'm fairly ignorant of the innards of database/sql.
It would be really convenient to be able to Scan directly into json.RawMessage types. I can always work around this by scanning into a []byte and converting to a json.RawMessage later.
The text was updated successfully, but these errors were encountered: