snowflakedb / gosnowflake

Go Snowflake Driver
Apache License 2.0
293 stars 122 forks source link

SNOW-521243: Scan still produces string when the destination is interface{} even after v1.6.0 #517

Closed YikSanChan closed 2 years ago

YikSanChan commented 2 years ago

Issue description

Scan still produces string when the destination is interface{} at v1.6.5. I open the issue because https://github.com/snowflakedb/gosnowflake/issues/513 is not really resolved. @sfc-gh-jbahk Can you help take a look?

Example code

Check this out https://github.com/YikSanChan/gosnowflake-bug-reproduce.

    for rows.Next() {
        var custkey, name, address, nationkey, phone, acctbal, mktsegment, comment string
        err = rows.Scan(&custkey, &name, &address, &nationkey, &phone, &acctbal, &mktsegment, &comment)
        if err != nil {
            log.Fatalf("failed to get result. err: %v", err)
        }
        // 60001 string
        // Customer#000060001 string
        // 9Ii4zQn9cX string
        // 14 string
        // 24-678-784-9652 string
        // 9957.560000 string
        // HOUSEHOLD string
        // l theodolites boost slyly at the platelets: permanently ironic packages wake slyly pend string
        fmt.Printf("%+v %T\n", custkey, custkey)
        fmt.Printf("%+v %T\n", name, name)
        fmt.Printf("%+v %T\n", address, address)
        fmt.Printf("%+v %T\n", nationkey, nationkey)
        fmt.Printf("%+v %T\n", phone, phone)
        fmt.Printf("%+v %T\n", acctbal, acctbal)
        fmt.Printf("%+v %T\n", mktsegment, mktsegment)
        fmt.Printf("%+v %T\n", comment, comment)
    }

custkey, for example, should be integer rather than string, as it is NUMBER(38, 0) on snowflake.

Configuration

Driver version (or git SHA): 1.6.5

Go version: 1.17.2

Server version: 5.43.1

Client OS: macOS 10.15.7

sfc-gh-jbahk commented 2 years ago

Can you run the .Scan() on the destination of interface{} type?

YikSanChan commented 2 years ago

Can you run the .Scan() on the destination of interface{} type?

@sfc-gh-jbahk thanks! I update my code https://github.com/YikSanChan/gosnowflake-bug-reproduce/commit/f2660bec1ec2110b3bfa505a2b0f177e11e92f42, then rerun, it still produces the same result - all strings.

60001 string
Customer#000060001 string
9Ii4zQn9cX string
14 string
24-678-784-9652 string
9957.560000 string
HOUSEHOLD string
l theodolites boost slyly at the platelets: permanently ironic packages wake slyly pend string
YikSanChan commented 2 years ago

@sfc-gh-jbahk hi can you help take a second look? thx!

sfc-gh-jbahk commented 2 years ago

@YikSanChan please use the WithHigherPrecision method (details found here: https://github.com/snowflakedb/gosnowflake/blob/master/doc.go#L227-L229).

YikSanChan commented 2 years ago

@sfc-gh-jbahk That works, thank you.