Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions server/doltgres_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"regexp"
"runtime/trace"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions testing/go/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"strconv"
"testing"

"github.com/jackc/pgx/v5/pgtype"

"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -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)
}