Skip to content

Simple query results differ from parameterized query results (strings vs. true data types) #211

Closed
@ffdwg

Description

@ffdwg

A "fast track" query (no placeholders / arguments) delivers string values (textRows) while a "normal" query (with arguments) delivers typed results (obv. using Prepare+Query & binaryRows) when using Scan interface function with empty interfaces (untyped!) as the value receivers.

To reproduce simply execute these (quite similar) examples on a table config with an id column (int unsigned) and a val column (double):

SELECT id, val FROM config;

You will receive two strings per row holding representations of id and val, whereas

SELECT id, val FROM config WHERE id>?;

with argument 0
delivers an int64 and a float64 value (as expected, right?).

Complete:

// mc, _ := sql.Open(...)
// ...
holderId := new(interface{})
holderVal := new(interface{})
res, _ := mc.Query("SELECT id, val FROM config")
for res.Next() {
    res.Scan(holderId, holderVal)
    // => holderId = *string("1"), holderVal = *string("1.11")
}
res.Close()
// ....
res = mc.Query("SELECT id, val FROM config WHERE id > ?", 0)
for res.Next() {
    res.Scan(holderId, holderVal)
    // => holderId = *int64(1), holderVal = *float64(1.11)
}
res.Close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions