Closed xorduna closed 2 years ago
Hi! The problem is that when you use pgx as a driver for the standard database/sql
library it can't handle JSON out of the box. You need to implement sql.Scanner
and sql.Valuer
interfaces for your map[string]interface{}
map type to make it work.
Check this article for detail:
https://medium.com/gothicism/how-to-handle-user-datatypes-in-golang-with-json-and-sql-database-a62d5304b0db
Hi!
I am trying to map a json object from the database to a map[string]interface{}
I am doing this because I want to reuse the struct and there can be an arbitrary number of columns queried from the database.
I managed to get it working with pgx driver, however, with database/sql I am getting an error that I don't understand ...
Scan error on column index 2, name "data": unsupported Scan, storing driver.Value type []uint8 into type *map[string]interface {}
I managed to get all the code in a single file, here it is:
What am I doing wrong? I tried to debug the problem going deeper into your library, but still I don't understand where some magic happens ..
Thank you very much!