0

I'm trying to get the users from a DB as follow,

var users []User
_, err := dbMap.Select(&users, "select id,username,acctstarttime,acctlastupdatedtime,acctstoptime from accounting order by id")

Here I'm using gorp. When there are null values present, this throws exception

 Select failed sql: Scan error on column index 3: unsupported driver -> Scan pair: <nil> -> *string 

How can I solve this issue?. Here I used gorp because of the ease of mapping the output to a struct array.

1 Answer 1

2

Make whatever acctstarttime maps to a pointer to the type instead of a value of the type.

if the col is null, the pointer will be nil.

that or you can use the sql.NullXXX types, but I usually don't like those since they make everything else weird.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.