2
0

Handle json/jsonb in binary to support CopyTo

fixes #189
This commit is contained in:
Jack Christensen
2016-10-01 10:58:04 -05:00
parent a9199847a8
commit f7b6b3f077
4 changed files with 111 additions and 9 deletions
+6 -2
View File
@@ -298,13 +298,17 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
if err != nil {
rows.Fatal(scanArgError{col: i, err: err})
}
} else if vr.Type().DataType == JsonOid || vr.Type().DataType == JsonbOid {
} else if vr.Type().DataType == JsonOid {
// Because the argument passed to decodeJSON will escape the heap.
// This allows d to be stack allocated and only copied to the heap when
// we actually are decoding JSON. This saves one memory allocation per
// row.
d2 := d
decodeJSON(vr, &d2)
} else if vr.Type().DataType == JsonbOid {
// Same trick as above for getting stack allocation
d2 := d
decodeJSONB(vr, &d2)
} else {
if err := Decode(vr, d); err != nil {
rows.Fatal(scanArgError{col: i, err: err})
@@ -393,7 +397,7 @@ func (rows *Rows) Values() ([]interface{}, error) {
values = append(values, d)
case JsonbOid:
var d interface{}
decodeJSON(vr, &d)
decodeJSONB(vr, &d)
values = append(values, d)
default:
rows.Fatal(errors.New("Values cannot handle binary format non-intrinsic types"))