Skip to content

Datetime precision breaks autoUpdateTime:nano #127

@pboguslawski

Description

@pboguslawski

Description

Column defined with

ModTime      int64       `gorm:"column:mod_time;not null;autoUpdateTime:nano;index:,composite:mod_time"`

is populated correctly with nano timestamps in sqlite3 but in mysql values are rounded to ms i.e. you get 1689751262515000000 instead of 1689751262515828345 in mysql column.

Workaround that works for us is to set datetimePrecision = 9 or force NowFunc i.e.

&gorm.Config{
 NowFunc: func() time.Time {
    return time.Now() // Here we use monotonic clock to avoid clock synchronization diffs see https://pkg.go.dev/time#hdr-Monotonic_Clocks
},
})

Adding ;precision:9 nor ;precision=9 field tag to ModTime column definition as above does not work.

Datetime precision logic should not be used probably for autoCreateTime nor autoUpdateTime columns because it defines time resolution on its own.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions