2
0

pgtype.JSON(B).Value now returns []byte

Allows scanning jsonb column into *json.RawMessage.

fixes #409
This commit is contained in:
Jack Christensen
2018-04-14 09:17:56 -05:00
parent 6556ef67cb
commit 5297846239
5 changed files with 58 additions and 1 deletions
+20
View File
@@ -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)
}