diff --git a/README.md b/README.md index 391e5ed..2fa757c 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ When passing arguments to queries, the driver supports the following Go data typ * integers * `bool` * `string` +* `[]byte` * slices * `trino.Numeric` - a string representation of a number * `time.Time` - passed to Trino as a timestamp with a time zone diff --git a/trino/serial.go b/trino/serial.go index 0bf7837..4c12230 100644 --- a/trino/serial.go +++ b/trino/serial.go @@ -15,6 +15,7 @@ package trino import ( + "encoding/hex" "encoding/json" "fmt" "reflect" @@ -147,9 +148,8 @@ func Serial(v interface{}) (string, error) { case string: return "'" + strings.Replace(x, "'", "''", -1) + "'", nil - // TODO - []byte should probably be matched to 'VARBINARY' in trino case []byte: - return "", UnsupportedArgError{"[]byte"} + return "X'" + strings.ToUpper(hex.EncodeToString(x)) + "'", nil case trinoDate: return fmt.Sprintf("DATE '%04d-%02d-%02d'", x.year, x.month, x.day), nil diff --git a/trino/serial_test.go b/trino/serial_test.go index 62ef0fd..7471db2 100644 --- a/trino/serial_test.go +++ b/trino/serial_test.go @@ -120,6 +120,16 @@ func TestSerial(t *testing.T) { value: false, expectedSerial: "false", }, + { + name: "bytes", + value: []byte{1, 255}, + expectedSerial: "X'01FF'", + }, + { + name: "empty bytes", + value: []byte{}, + expectedSerial: "X''", + }, { name: "date", value: Date(2017, 7, 10),