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

Invalid sqlite date rendering CAST AS DATE, DATEDIFF and DATEADD #351

Closed
MaximMoinat opened this issue Nov 22, 2023 · 1 comment
Closed

Comments

@MaximMoinat
Copy link
Contributor

MaximMoinat commented Nov 22, 2023

For sqlite, rendering of DATEADD(month,@months,@date) is not valid.
Underlying issue is that for sqllite the plural 'months' is used, where it should be singular 'month'.

sqlite,"DATEADD(months,@months,@date)","CAST(STRFTIME('%s', DATETIME(@date, 'unixepoch', (@months)||' months')) AS REAL)"

@MaximMoinat MaximMoinat changed the title Months in sqllite dateadd replacement pattern should be month DATEADD(month,@months,@date) not rendered for sqllite Nov 22, 2023
@MaximMoinat MaximMoinat changed the title DATEADD(month,@months,@date) not rendered for sqllite Invalid sqlite date rendering CAST AS DATE, DATEDIFF and DATEADD Dec 12, 2023
@MaximMoinat
Copy link
Contributor Author

MaximMoinat commented Dec 12, 2023

In addition, the following also produce invalid sql:

  • CAST('1900-01-01' AS DATE) renders into CAST(STRFTIME('%s', SUBSTR(CAST('1900-01-01' AS TEXT), 1, 4) || '-' || SUBSTR(CAST('1900-01-01' AS TEXT), 5, 2) || '-' || SUBSTR(CAST('1900-01-01' AS TEXT), 7))
    • This assumes 19000101 was used as input date format. The substrings on indexes 5,2 and 7 give '-0' and '1-01' as date parts respectively, which produces an malformed date string when concatenated again.
    • Fixed by using '19000101' as input date format. Is this preferred date format documented somewhere?
  • DATEDIFF(d, start, end) renders into JULIANDAY(end, 'unixepoch') - JULIANDAY(start, 'unixepoch')
    • This causes issues when further calculation is done with the difference (e.g. multiplied by 2). The replacement should be in between parenthesis (JULIANDAY(end, 'unixepoch') - JULIANDAY(start, 'unixepoch'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants