Skip to content

Commit 7788e7e

Browse files
author
James Cor
committed
more fixes
1 parent a609bb6 commit 7788e7e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

enginetest/queries/queries.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10232,6 +10232,12 @@ from typestable`,
1023210232
{"981228896.000000"},
1023310233
},
1023410234
},
10235+
{
10236+
Query: "select unix_timestamp('2001-02-03 12:34:56.1234567');",
10237+
Expected: []sql.Row{
10238+
{"981228896.123457"},
10239+
},
10240+
},
1023510241
}
1023610242

1023710243
var KeylessQueries = []QueryTest{

sql/expression/function/date.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ func NewUnixTimestamp(args ...sql.Expression) (sql.Expression, error) {
484484
dateStr = strings.TrimSpace(dateStr[idx:])
485485
scale := uint8(len(dateStr) - 1)
486486
if scale > 0 {
487+
if scale > 6 {
488+
scale = 6
489+
}
487490
typ, tErr := types.CreateDecimalType(19, scale)
488491
if tErr != nil {
489492
return nil, tErr

sql/types/datetime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ func ConvertToTime(v interface{}, t datetimeType) (time.Time, error) {
198198
return zeroTime, nil
199199
}
200200

201-
// Truncate the date to the precision of this type
201+
// Round the date to the precision of this type
202202
truncationDuration := time.Second
203203
truncationDuration /= time.Duration(precisionConversion[t.precision])
204-
res = res.Truncate(truncationDuration)
204+
res = res.Round(truncationDuration)
205205

206206
switch t.baseType {
207207
case sqltypes.Date:

0 commit comments

Comments
 (0)