diff --git a/server/doltgres_handler.go b/server/doltgres_handler.go index 0f79ebf022..6b48238e06 100644 --- a/server/doltgres_handler.go +++ b/server/doltgres_handler.go @@ -26,6 +26,7 @@ import ( "regexp" "runtime/trace" "strconv" + "strings" "sync" "time" @@ -413,6 +414,22 @@ func (h *DoltgresHandler) convertBindParameterToString(typ uint32, value []byte, s := u.String() bindVarString = &s } + case typ == pgtype.TextArrayOID && isBinaryFormat: + if value != nil { + m := pgtype.NewMap() + var textArray []string + scanPlan := m.PlanScan(pgtype.TextArrayOID, pgtype.BinaryFormatCode, &textArray) + err = scanPlan.Scan(value, &textArray) + if err != nil { + return nil, err + } + quotedArray := make([]string, len(textArray)) + for i, v := range textArray { + quotedArray[i] = `"` + strings.ReplaceAll(v, `"`, `\"`) + `"` + } + formattedArray := "{" + strings.Join(quotedArray, ",") + "}" + bindVarString = &formattedArray + } default: // For text format or types that can handle binary-to-string conversion if err := h.pgTypeMap.Scan(typ, formatCode, value, &bindVarString); err != nil { diff --git a/testing/go/binding_test.go b/testing/go/binding_test.go index 62cca58e35..1585bbd80e 100644 --- a/testing/go/binding_test.go +++ b/testing/go/binding_test.go @@ -18,6 +18,8 @@ import ( "strconv" "testing" + "github.com/jackc/pgx/v5/pgtype" + "github.com/stretchr/testify/require" ) @@ -46,3 +48,25 @@ func TestBindingWithOidZero(t *testing.T) { result := resultReader.Read() require.NoError(t, result.Err) } + +func TestBindingWithTextArray(t *testing.T) { + ctx, connection, controller := CreateServer(t, "postgres") + defer controller.Stop() + conn := connection.Default + + m := pgtype.NewMap() + textArray := []string{"foo", "bar"} + + plan := m.PlanEncode(pgtype.TextArrayOID, pgtype.BinaryFormatCode, textArray) + encodedArr, err := plan.Encode(textArray, nil) + require.NoError(t, err) + + args := [][]byte{encodedArr} + paramOIDs := []uint32{1009} + paramFormats := []int16{1} + sql := "SELECT $1::text[]" + + resultReader := conn.PgConn().ExecParams(ctx, sql, args, paramOIDs, paramFormats, nil) + result := resultReader.Read() + require.NoError(t, result.Err) +}