pgtype.JSON(B).Value now returns []byte
Allows scanning jsonb column into *json.RawMessage. fixes #409
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
@@ -1466,3 +1467,22 @@ func TestSimpleQueryLifeCycle(t *testing.T) {
|
||||
|
||||
ensureConnValid(t, db)
|
||||
}
|
||||
|
||||
// https://github.com/jackc/pgx/issues/409
|
||||
func TestScanJSONIntoJSONRawMessage(t *testing.T) {
|
||||
db := openDB(t)
|
||||
defer closeDB(t, db)
|
||||
|
||||
var msg json.RawMessage
|
||||
|
||||
err := db.QueryRow("select '{}'::jsonb").Scan(&msg)
|
||||
if err != nil {
|
||||
t.Fatalf("QueryRow / Scan failed: %v", err)
|
||||
}
|
||||
|
||||
if bytes.Compare([]byte("{}"), []byte(msg)) != 0 {
|
||||
t.Fatalf("Expected %v, got %v", []byte("{}"), msg)
|
||||
}
|
||||
|
||||
ensureConnValid(t, db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user