Fix hstore with empty string values

This commit is contained in:
Jack Christensen 2020-06-06 10:26:34 -05:00
parent 937aec9841
commit 36944b232f
2 changed files with 3 additions and 1 deletions

View File

@ -168,6 +168,7 @@ func (src Hstore) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
firstPair := true
inElemBuf := make([]byte, 0, 32)
for k, v := range src.Map {
if firstPair {
firstPair = false
@ -178,7 +179,7 @@ func (src Hstore) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
buf = append(buf, quoteHstoreElementIfNeeded(k)...)
buf = append(buf, "=>"...)
elemBuf, err := v.EncodeText(ci, nil)
elemBuf, err := v.EncodeText(ci, inElemBuf)
if err != nil {
return nil, err
}

View File

@ -15,6 +15,7 @@ func TestHstoreTranscode(t *testing.T) {
values := []interface{}{
&pgtype.Hstore{Map: map[string]pgtype.Text{}, Status: pgtype.Present},
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text(""), "bar": text(""), "baz": text("123")}, Status: pgtype.Present},
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar")}, Status: pgtype.Present},
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar"), "baz": text("quz")}, Status: pgtype.Present},
&pgtype.Hstore{Map: map[string]pgtype.Text{"NULL": text("bar")}, Status: pgtype.Present},