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 for time.Duration #4954

Closed
gopherbot opened this issue Mar 1, 2013 · 6 comments
Closed

database/sql: Support for time.Duration #4954

gopherbot opened this issue Mar 1, 2013 · 6 comments
Milestone

Comments

@gopherbot
Copy link
Contributor

by raul.san@sent.com:

Support for that Scan (http://golang.org/pkg/database/sql/#Scanner) can read
time.Duration
@davecheney
Copy link
Contributor

Comment 1:

What SQL datatype represents a time.Duration ?

@gopherbot
Copy link
Contributor Author

Comment 2 by raul.san@sent.com:

+ Oracle implements SQL92's INTERVAL DAY TO SECOND
+ Mysql has TIME
+ PostreSQL has the INTERVAL
+ SQLite3 doesn't support any kind of time fields (datetime, time,
interval), but accepts all as legal types so could be used INTEGER.

@gopherbot
Copy link
Contributor Author

Comment 3 by raul.san@sent.com:

SQLite3 in SQLAlchemy was implemented using a string with SQL datatype "TEXT":
https://bitbucket.org/sqlalchemy/sqlalchemy/src/02615a0fde68f339969c806460462ca1fd5a98f2/lib/sqlalchemy/dialects/sqlite/base.py?at=default#cl-309
There was a discussion in Django forums about its implementation in Django's ORM:
https://groups.google.com/forum/?hl=en&fromgroups=#!topic/django-developers/0yMWznlk268

@kisielk
Copy link
Contributor

kisielk commented Mar 2, 2013

Comment 4:

As I mentioned in a github issue (https://github.com/bmizerany/pq/issues/78) for the pq
driver I don't think this is possible for Postgres. The interval datatype is a 12-byte
value with a much larger range than time.Duration:
http://www.postgresql.org/docs/9.2/static/datatype-datetime.html
It seems Oracle's interval type supports up to 9 digits in the days field, which is also
larger than time.Duration (290 years is ~105920 days)
MySQL is more limited, the range is +/- 839 hours.

@gopherbot
Copy link
Contributor Author

Comment 5 by raul.san@sent.com:

Then, since time.Duration is an int64
(http://golang.org/src/pkg/time/time.go?s=12544:12563#L374), could be used a SQL
datatype to store an int64:
+ BIGINT in MySQL
+ bigint in PostgreSQL
+ INTEGER in SQLite3

@bradfitz
Copy link
Contributor

bradfitz commented Mar 3, 2013

Comment 6:

If you need a custom type, you can implement sql.Scanner and driver.Valuer.
I would like to keep the database/sql and database/sql/driver packages how they are.

Status changed to WontFix.

@mikioh mikioh changed the title sql: Support for time.Duration database/sql: Support for time.Duration Feb 18, 2015
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants