Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
database/sql: Provide format string for SQL dates, times, and datetimes #30991
Go helpfully declares a predefined format string for parsing and formatting RFC3339 timestamps. Unfortunately, SQL uses a slightly different format, essentially replacing the
var SQLTimestampFormat = "2006-01-02 15:04:05"
Higher level API's supposedly offer automatic marshaling between SQL literals and Go objects, such as ORM's and special SQL driver options. However, sometimes lower level access is needed. In these cases, it is helpful to be able to use a predefined, tested format string rather than having to write our own.
The ANSI SQL specification, PostgreSQL, MySQL/MariaDB, MSSQL, Oracle, BigQuery, Spanner, SQLite, MonetDB, Virtuoso, and Firebird support the aforementioned
We should probably bind this format string constant as
Another option is to add a method to the SQL driver interfaces for obtaining the driver's preferred date, time, and timestamp formats. The MySQL driver doesn't currently implement this, for example, but we could require them to in a future API.
DB2 appears to expects a dash, deviating from not only RFC3339 but ANSI SQL as well. C'est parfait merde.
@mcandre Thanks for the info. (small nit it would be a const if added).
Some databases also support timezones such as timestampz or datetimeoffset. I have two additional question: