Skip to content

Commit 859e4fc

Browse files
authored
Merge pull request #3123 from dolthub/angela/decimal_unique_key
Support decimal unique keys
2 parents f8574b7 + d606316 commit 859e4fc

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
@@ -10882,6 +10882,19 @@ where
1088210882
},
1088310883
},
1088410884
},
10885+
{
10886+
Name: "decimal unique key",
10887+
SetUpScript: []string{
10888+
"create table t (i int primary key, d decimal(10, 2) unique)",
10889+
"insert into t values (1, 1)",
10890+
},
10891+
Assertions: []ScriptTestAssertion{
10892+
{
10893+
Query: "insert into t values (2, 1)",
10894+
ExpectedErr: sql.ErrUniqueKeyViolation,
10895+
},
10896+
},
10897+
},
1088510898

1088610899
// Date Tests
1088710900
{

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)