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

.Get() #63

Closed
robfordww opened this issue Aug 20, 2021 · 1 comment · Fixed by #74 or anton7r/scany#1
Closed

.Get() #63

robfordww opened this issue Aug 20, 2021 · 1 comment · Fixed by #74 or anton7r/scany#1

Comments

@robfordww
Copy link

robfordww commented Aug 20, 2021

I have noticed that the.Get()method of Scany and Sqlx varies when you try to scan a select now() into a var t time.Time. Scany.Get() treats the &t as a struct with missing fields, while sqlx.Get() does write the value into the variable. Is this "by design"? I noticed this when switching from Sqlx to Scany.

@georgysavva
Copy link
Owner

Hello! This is indeed a limitation in the current scany implementation. See this comment for more details: #33 (comment)
I have plans to fix it in the future, but for now, a workaround to scan using scany would be:

type Row struct {
    T time.Time
}
row := &Row{}
if err := pgxscan.Get(ctx, pgxConn, row, "select now() as t"); err != nil {
    return nil, err
}
fmt.Println(row.T)

georgysavva added a commit that referenced this issue Dec 23, 2021
This PR adds an exception for scannable types to be treated as primitive types rather than structs or maps.
Fixes: #63, #33, #73.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants