jmoiron / sqlx

general purpose extensions to golang's database/sql
http://jmoiron.github.io/sqlx/
MIT License
16.14k stars 1.08k forks source link

Get() scanning to *struct #450

Open Albert221 opened 6 years ago

Albert221 commented 6 years ago

Hey, if I'm using db.Select() with destination being []*someStruct, then everything is okay, but if I use db.Get() with destination being *someStruct then I'm getting similar error:

scannable dest type ptr with >1 columns (6) in result

And I have to pass a normal struct as a destination, not its pointer. I'm just wondering whether this behaviour is intended?

feelfreelinux commented 6 years ago

I'm having the same problem.

Thanks for this awesome library

nianglao commented 6 years ago

@Albert221 Can you provide more details? Like what your someStruct is, how to you call db.Get()?

db.Get() will call scanAny() in which if scannable && len(columns) > 1 { return fmt.Errorf("scannable dest type %s with >1 columns (%d) in result", base.Kind(), len(columns)) }

Perhaps you can debug with scanAny() in sqlx.go

glaslos commented 6 years ago

@Albert221 and @feelfreelinux your query returns more than one row. db.Get is intended to handle only one row being returned. Either use db.Select or LIMIT 1 your query.

DrDog47 commented 6 years ago

@glaslos Hello, I have the same issue. And the problem is that my query returns only one row. I tried to add LIMIT 1 and it's not working too. I'm using sqlx to query Clickhouse DB.

Albert221 commented 5 years ago

@glaslos debugger showed me fields from only one row, so I don't think that returning more than one row is the cause of it here

zhanghanyun commented 5 years ago

@Albert221 Because the *someStruct is not a struct pointer