Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime precision breaks autoUpdateTime:nano #127

Open
pboguslawski opened this issue Jul 19, 2023 · 0 comments
Open

Datetime precision breaks autoUpdateTime:nano #127

pboguslawski opened this issue Jul 19, 2023 · 0 comments
Assignees

Comments

@pboguslawski
Copy link

pboguslawski commented Jul 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants