We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I used my own Scanner implementation to scan values. I found pg "character varying" column comes as []byte not string. is it a bug ?
And "numeric" type mapped to []byte How should I differentiate my column is string or byte array?
Any Suggestion?
Example : Name column in below example fall as []byte not a string.
package main import ( "database/sql" "fmt" "time" _ "github.com/lib/pq" ) func main() { db, _ := sql.Open("postgres", "user=postgres password=root dbname=test sslmode=disable") rows, _ := db.Query("SELECT 1 as ID, 'Jack' as NAME") defer rows.Close() columns, _ := rows.Columns() for rows.Next() { row := make([]interface{}, len(columns)) for idx := range columns { row[idx] = new(MetalScanner) } err := rows.Scan(row...) if err != nil { fmt.Println(err) } for idx, column := range columns { var scanner = row[idx].(*MetalScanner) fmt.Println(column, ":", scanner.value) } } } type MetalScanner struct { valid bool value interface{} } func (scanner *MetalScanner) getBytes(src interface{}) []byte { if a, ok := src.([]uint8); ok { return a } return nil } func (scanner *MetalScanner) Scan(src interface{}) error { switch src.(type) { case int64: if value, ok := src.(int64); ok { scanner.value = value scanner.valid = true } case float64: if value, ok := src.(float64); ok { scanner.value = value scanner.valid = true } case bool: if value, ok := src.(bool); ok { scanner.value = value scanner.valid = true } case string: value := scanner.getBytes(src) scanner.value = string(value) scanner.valid = true case []byte: value := scanner.getBytes(src) scanner.value = value scanner.valid = true case time.Time: if value, ok := src.(time.Time); ok { scanner.value = value scanner.valid = true } case nil: scanner.value = nil scanner.valid = true } return nil }
The text was updated successfully, but these errors were encountered:
I believe it's fixed by e2402a7.
Sorry, something went wrong.
Looks to me like this was indeed fixed in #436. Please let me know if you disagree.
No branches or pull requests
I used my own Scanner implementation to scan values. I found pg "character varying" column comes as []byte not string. is it a bug ?
And "numeric" type mapped to []byte
How should I differentiate my column is string or byte array?
Any Suggestion?
Example : Name column in below example fall as []byte not a string.
The text was updated successfully, but these errors were encountered: