sqlglot
sqlglot copied to clipboard
SQLite: date('now') is transpiled to CAST('now' AS DATE)
'now' is a special time value in SQLite's date functions, but sqlglot treats it as a regular string, so the output fails at runtime:
import sqlglot
sqlglot.transpile("SELECT date('now'), strftime('%Y', 'now')", read="sqlite", write="duckdb")
# ["SELECT CAST('now' AS DATE), STRFTIME(CAST('now' AS TIMESTAMP), '%Y')"]
# DuckDB: Conversion Error: invalid date field format: "now"
Expected something like SELECT CURRENT_DATE, STRFTIME(CURRENT_TIMESTAMP, '%Y'). The one-argument strftime(fmt) path already fills in CURRENT_TIMESTAMP, so mapping the 'now' literal the same way seems consistent.
One caveat: SQLite's 'now' is UTC, while CURRENT_DATE in most targets follows the session time zone.
Tested on main (87bb5d3d).
Official Documentation https://www.sqlite.org/lang_datefunc.html#time_values ("The string 'now' is converted into the current date and time")