mirror of https://github.com/jackc/pgx.git
fix: handle null interface for json
When using `scany` I encountered the following case. This seems to fix it. Looks like null `jsonb` columns cause the problem. If you create a table like below you can see that the following code fails. Is this expected? ```sql CREATE TABLE test ( a int4 NULL, b int4 NULL, c jsonb NULL ); INSERT INTO test (a, b, c) VALUES (1, null, null); ``` ```go package main import ( "context" "log" "github.com/georgysavva/scany/v2/pgxscan" "github.com/jackc/pgx/v5" ) func main() { var rows []map[string]interface{} conn, _ := pgx.Connect(context.Background(), , ts.PGURL().String()) // this will fail with can't scan into dest[0]: cannot scan NULL into *interface {} err := pgxscan.Select(context.Background(), conn, &rows, `SELECT c from test`) // this works // err = pgxscan.Select(context.Background(), conn, &rows, `SELECT a,b from test`) if err != nil { panic(err) } log.Printf("%+v", rows) } ```pull/1565/head
parent
7af80ae8a6
commit
2a653b4a8d
|
@ -150,7 +150,7 @@ func (scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error {
|
|||
if dstValue.Kind() == reflect.Ptr {
|
||||
el := dstValue.Elem()
|
||||
switch el.Kind() {
|
||||
case reflect.Ptr, reflect.Slice, reflect.Map:
|
||||
case reflect.Ptr, reflect.Slice, reflect.Map, reflect.Interface:
|
||||
el.Set(reflect.Zero(el.Type()))
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue