Sqlx: Get() scanning to *struct

Created on 5 Sep 2018  路  6Comments  路  Source: jmoiron/sqlx

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?

Most helpful comment

@Albert221 Because the *someStruct is not a struct pointer

All 6 comments

I'm having the same problem.

Thanks for this awesome library

@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

@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.

@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.

@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

@Albert221 Because the *someStruct is not a struct pointer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ascepanovic picture ascepanovic  路  6Comments

plandem picture plandem  路  5Comments

resal81 picture resal81  路  5Comments

x1unix picture x1unix  路  4Comments

davisford picture davisford  路  5Comments