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
database/sql: decode time.Time into *time.Time #22300
Comments
It's unusual to use values of type |
What's unusual about it? This seems like the most type-safe approach to loading time values from a SQL database. My use case is this:
Decoding into It would be way more efficient to just have a special case for The reason I'm raising this issue is because I have a production service which has a significant amount of memory allocated in |
Simplified code example of what I meant: rows, err := db.QueryContext(ctx, "select ..., created_at, updated_at from ...")
if err != nil {
return err
}
var ...
var createdAt time.Time
var updatedAt time.Time
for rows.Next() {
err := rows.Scan(..., &createdAt, &updated) // here are the *time.Time
...
} |
I’m pretty sure what you wrote works today, I’ve written the same recently.
… On 17 Oct 2017, at 13:14, Achille ***@***.***> wrote:
Simplified code example of what I meant:
rows, err := db.QueryContext(ctx, "select ...")
if err != nil {
return err
}
var ...
var createdAt time.Time
var updatedAt time.Time
for rows.Next() {
err := rows.Scan(..., &createdAt, &updated) // here are the *time.Time
...
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Indeed, my point isn't that it doesn't work, it's that the Cycling back, my original question was: is there a reason that the current implementation didn't special case the assignment from If there are no reasons I'll be happy to contribute a patch. |
CC @kardianos |
Seems reasonable to me, given that we already have special handling of |
SGTM. I'll send a CL soon. |
Thanks for the quick responses you all! |
Change https://golang.org/cl/73232 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Converting from a
time.Time
value returned by the SQL driver into atime.Time
value uses a code path based on reflection, where it could be a simple assignment. Is there any reason why thedatabase/sql
package would not want to directly assime the time values?(none that I can think of right now).
What did you expect to see?
I believe we could add this as an optimization to decode time values into time values (which is a very common case):
What did you see instead?
https://github.com/golang/go/blob/master/src/database/sql/convert.go#L271-L288
(notice there are only cases to decode time values into string or byte slices)
The text was updated successfully, but these errors were encountered: