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

Null types: unsupported Scan, storing driver.Value type <nil> into type *time.Time #273

Closed
kheraankit opened this issue Nov 14, 2019 · 3 comments
Labels
enhancement The issue is a request for improvement or a new feature jira copied to JIRA

Comments

@kheraankit
Copy link

Issue description

Try to fetch a row from a table that has a TIMESTAMP_LTZ or other date/time column type and make sure the value in the table for that column is null. Use the scan method to fetch the row and provide a *time.Time destination to scan the value of the column into.

What should happen?
Provide a NullTime type as provided by other drivers
What's happening?
unsupported Scan, storing driver.Value type into type *time.Time

@smtakeda
Copy link
Contributor

Is this go1.13 new feature?

@smtakeda smtakeda added bug Erroneous or unexpected behaviour enhancement The issue is a request for improvement or a new feature jira copied to JIRA and removed bug Erroneous or unexpected behaviour labels Nov 14, 2019
@kheraankit
Copy link
Author

The way I am trying to get around is by defining my own NullTime type but feel that the driver should provide this type and do the conversion etc... if needed.

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

// Scan implements the Scanner interface for NullTime
func (nt *NullTime) Scan(value interface{}) error {
	if value == nil {
		nt.Time, nt.Valid = time.Time{}, false
		return nil
	}

	switch v := value.(type) {
	case time.Time:
                // . snowflake already has converted to time.Time
		nt.Time, nt.Valid = v, true
		return nil
	}
	return fmt.Errorf("Can't convert %T to time.Time", value)
}

@smtakeda
Copy link
Contributor

smtakeda commented Nov 16, 2019

I'm a bit confused. NullTime is provided from Go 1.13, and other database started deprecating their own NullTime:

Why Snowflake needs to introduce it now? In my understanding, NullTime was added to other drivers, because it didn't exist before. Now why not upgrading Go to 1.13? Do I miss something? Can you please elaborate your use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is a request for improvement or a new feature jira copied to JIRA
Projects
None yet
Development

No branches or pull requests

2 participants