Skip to content

Commit d606316

Browse files
committed
Support decimal unique keys
1 parent 7bc2294 commit d606316

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

enginetest/queries/script_queries.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11045,6 +11045,19 @@ where
1104511045
},
1104611046
},
1104711047
},
11048+
{
11049+
Name: "decimal unique key",
11050+
SetUpScript: []string{
11051+
"create table t (i int primary key, d decimal(10, 2) unique)",
11052+
"insert into t values (1, 1)",
11053+
},
11054+
Assertions: []ScriptTestAssertion{
11055+
{
11056+
Query: "insert into t values (2, 1)",
11057+
ExpectedErr: sql.ErrUniqueKeyViolation,
11058+
},
11059+
},
11060+
},
1104811061

1104911062
// Date Tests
1105011063
{

memory/table_editor.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"reflect"
2020
"strings"
2121

22+
"github.com/shopspring/decimal"
23+
2224
"github.com/dolthub/go-mysql-server/internal/cmap"
2325
"github.com/dolthub/go-mysql-server/sql"
2426
"github.com/dolthub/go-mysql-server/sql/types"
@@ -355,14 +357,25 @@ func columnsMatch(colIndexes []int, prefixLengths []uint16, row sql.Row, row2 sq
355357
v2 = v[:prefixLength]
356358
}
357359
}
358-
if v, ok := v1.([]byte); ok {
359-
v1 = string(v)
360-
}
361-
if v, ok := v2.([]byte); ok {
362-
v2 = string(v)
363-
}
364-
if v1 != v2 {
365-
return false
360+
361+
if v1Decimal, ok := v1.(decimal.Decimal); ok {
362+
if v2Decimal, ok := v2.(decimal.Decimal); ok {
363+
if !v1Decimal.Equal(v2Decimal) {
364+
return false
365+
}
366+
} else {
367+
return false
368+
}
369+
} else {
370+
if v, ok := v1.([]byte); ok {
371+
v1 = string(v)
372+
}
373+
if v, ok := v2.([]byte); ok {
374+
v2 = string(v)
375+
}
376+
if v1 != v2 {
377+
return false
378+
}
366379
}
367380
}
368381
return true

0 commit comments

Comments
 (0)