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
4 changes: 2 additions & 2 deletions sql/types/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func ColumnTypeToType(ct *sqlparser.ColumnType) (sql.Type, error) {
}
}
return CreateString(sqltypes.Char, length, sql.Collation_utf8mb3_general_ci)
case "varchar", "character varying":
case "varchar", "char varying", "character varying":
collation, err := sql.ParseCollation(&ct.Charset, &ct.Collate, ct.BinaryCollate)
if err != nil {
return nil, err
Expand All @@ -281,7 +281,7 @@ func ColumnTypeToType(ct *sqlparser.ColumnType) (sql.Type, error) {
}
}
return CreateString(sqltypes.VarChar, length, collation)
case "nvarchar", "national varchar", "national character varying":
case "nchar varchar", "nchar varying", "nvarchar", "national varchar", "national char varying", "national character varying":
if ct.Length == nil {
return nil, fmt.Errorf("VARCHAR requires a length")
}
Expand Down
42 changes: 42 additions & 0 deletions sql/types/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"testing"

"github.com/dolthub/vitess/go/sqltypes"
"github.com/dolthub/vitess/go/vt/sqlparser"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -116,3 +117,44 @@ func TestColumnTypeToType_Time(t *testing.T) {
})
}
}

func TestColumnCharTypes(t *testing.T) {
test := []struct {
typ string
len int64
exp sql.Type
}{
{
typ: "nchar varchar",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 30, collation: 33},
},
{
typ: "char varying",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 40},
},
{
typ: "nchar varying",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 30, collation: 33},
},
{
typ: "national char varying",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 30, collation: 33},
},
}

for _, test := range test {
t.Run(fmt.Sprintf("%v %v", test.typ, test.exp), func(t *testing.T) {
ct := &sqlparser.ColumnType{
Type: test.typ,
Length: &sqlparser.SQLVal{Type: sqlparser.IntVal, Val: []byte(fmt.Sprintf("%v", test.len))},
}
res, err := ColumnTypeToType(ct)
assert.NoError(t, err)
assert.Equal(t, test.exp, res)
})
}
}