Cockroach: sql: Scan error on column index 1: unsupported Scan, storing driver.Value type []uint8 into type *[]string

Created on 20 Aug 2019  路  5Comments  路  Source: cockroachdb/cockroach

Describe the problem

It is not possible to scan a TEXT ARRAY database column into a []string struct field.

To Reproduce

type Foo struct {
    Bars []string `json:"bars"`
}
CREATE TABLE IF NOT EXISTS foos (
  id BIGSERIAL NOT NULL,
  bars TEXT ARRAY NOT NULL,
  PRIMARY KEY (id)
);
...
for rows.Next() {
    var foo Foo
    if err := rows.Scan(&foo.Id, &foo.Bars); err != nil {
        return Foo{}, err
    }
    return foo, nil
}



md5-cb1a9438c4b0904d634e0c528a522e8d



sql: Scan error on column index 1: unsupported Scan, storing driver.Value type []uint8 into type *[]string

Environment:

  • CockroachDB version v19.1.3
  • Server OS: Debian
  • Client app: github.com/lib/pq

Additional context
I suppose this error does not come from the driver, since i could not find any such issue in the lib/pq repo...

Most helpful comment

Bars pq.StringArray json:"bars"

All 5 comments

I think this error comes from Go's database/sql. I'm not sure what the cause is, but I'm fairly sure that this isn't an issue with CockroachDB.

@jordanlewis Thanks for the hint!
In fact the driver needs assistance with array types:

...
for rows.Next() {
    var foo Foo
    if err := rows.Scan(&foo.Id, pq.Array(&foo.Bars)); err != nil {
        return Foo{}, err
    }
    return foo, nil
}

@cgebe no problem, glad you figured it out!

Bars pq.StringArray json:"bars"

dengsibao , you da man! That's exactly what was needed!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nvanbenschoten picture nvanbenschoten  路  3Comments

couchand picture couchand  路  3Comments

richardanaya picture richardanaya  路  3Comments

rafiss picture rafiss  路  3Comments

awoods187 picture awoods187  路  3Comments