Skip to content
New issue

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

database/sql: support time.Time and arrays #17834

Closed
anoopbhat opened this issue Nov 7, 2016 · 7 comments
Closed

database/sql: support time.Time and arrays #17834

anoopbhat opened this issue Nov 7, 2016 · 7 comments
Assignees
Milestone

Comments

@anoopbhat
Copy link

@anoopbhat anoopbhat commented Nov 7, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.3 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/Catalog"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

What did you do?

Running a query in postgresql where a column in a table is an array.

column description
consistencydate | timestamp without time zone[] | not null

A query i'm running is

    rows, err := c.db.Query("select parent, filename, mtime, size, mode, consistencydate from " + appTableName + " where parent ilike '%' || $1 || '%' or filename ilike '%' || $2 || '%'", fs.Name, fs.Name)

    if err != nil {
            return nil, errors.WithStack(err)
    }

    defer rows.Close()

    for rows.Next() {
            var f models.FileRecord
            if err := rows.Scan(&f.Parent, &f.Filename, &f.LastModificationTime, &f.Size, &f.Mode, &f.ConsistencyDate); err != nil {
                    return nil, errors.WithStack(err)
            }

            records = append(records, &f)
    }

    if err := rows.Err(); err != nil {
            return nil, errors.WithStack(err)
    }

    return records, nil

What did you expect to see?

a proper conversion from a timestamp without timezone[] field to []time.Time

What did you see instead?

an error
2016/11/07 13:40:15 sql: Scan error on column index 5: unsupported Scan, storing driver.Value type []uint8 into type *[]time.Time

I think that sql.Scan() doesn't support []time.Time. If there's no plan to support it, that's ok. I just want to know.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 7, 2016

@anoopbhat anoopbhat changed the title 2016/11/07 13:40:15 sql: Scan error on column index 5: unsupported Scan, storing driver.Value type []uint8 into type *[]time.Time database/sql: Scan error on column index 5: unsupported Scan, storing driver.Value type []uint8 into type *[]time.Time Nov 7, 2016
@kardianos
Copy link
Contributor

@kardianos kardianos commented Nov 7, 2016

Which database driver are you using?

@quentinmit quentinmit added this to the Go1.8Maybe milestone Nov 7, 2016
@anoopbhat
Copy link
Author

@anoopbhat anoopbhat commented Nov 8, 2016

the postgresql driver pq.

import (
"database/sql"
_ "github.com/lib/pq"
"github.com/pkg/errors"
"strings"
)

@rsc rsc modified the milestones: Go1.9, Go1.8Maybe Nov 11, 2016
@derekperkins
Copy link

@derekperkins derekperkins commented Nov 28, 2016

This issue seems like it is combining two separate limitations with database/sql.

  1. No native time.Time support
  2. No support for slices #16235

Since there is already an issue for slice support, I think this issue should be retitled to database/sql: Natively support time.Time.

This would be awesome for 1.9.

@kardianos kardianos self-assigned this Nov 28, 2016
@kardianos kardianos changed the title database/sql: Scan error on column index 5: unsupported Scan, storing driver.Value type []uint8 into type *[]time.Time database/sql: support time.Time and arrays Nov 28, 2016
@kardianos
Copy link
Contributor

@kardianos kardianos commented Dec 4, 2016

Be aware of other custom types: denisenkom/go-mssqldb#61

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 23, 2017

CL https://golang.org/cl/38533 mentions this issue.

gopherbot pushed a commit that referenced this issue May 18, 2017
Previously all arguments were passed through driver.IsValid.
This checked arguments against a few fundamental go types and
prevented others from being passed in as arguments.

The new interface driver.NamedValueChecker may be implemented
by both driver.Stmt and driver.Conn. This allows
this new interface to completely supersede the
driver.ColumnConverter interface as it can be used for
checking arguments known to a prepared statement and
arbitrary query arguments. The NamedValueChecker may be
skipped with driver.ErrSkip after all special cases are
exhausted to use the default argument converter.

In addition if driver.ErrRemoveArgument is returned
the argument will not be passed to the query at all,
useful for passing in driver specific per-query options.

Add a canonical Out argument wrapper to be passed
to OUTPUT parameters. This will unify checks that need to
be written in the NameValueChecker.

The statement number check is also moved to the argument
converter so the NamedValueChecker may remove arguments
passed to the query.

Fixes #13567
Fixes #18079
Updates #18417
Updates #17834
Updates #16235
Updates #13067
Updates #19797

Change-Id: I89088bd9cca4596a48bba37bfd20d987453ef237
Reviewed-on: https://go-review.googlesource.com/38533
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@kardianos
Copy link
Contributor

@kardianos kardianos commented May 30, 2017

The above CL will allow drivers that want to support time.Time and arrays to do so.

@kardianos kardianos closed this May 30, 2017
@golang golang locked and limited conversation to collaborators May 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.