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

SQL syntax error in aggregates_3_4.sql? #7

Open
sebxwolf opened this issue Apr 1, 2020 · 1 comment
Open

SQL syntax error in aggregates_3_4.sql? #7

sebxwolf opened this issue Apr 1, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@sebxwolf
Copy link

sebxwolf commented Apr 1, 2020

Describe the bug
I tried running queries in aggregates_3_4.sql but got an SQL syntax error due to the 'week' in quotes.

To Reproduce
Run the sql queries in aggregates_3_4.sql

Expected behavior
Create the tables

Additional context
Maybe this is supposed to run in an environment with different flavor of SQL? I tried running it in Spark. But an SQL syntax validator gave me the same error: https://www.eversql.com/sql-syntax-check-validator/

Suggested solution
Remove the quotes and it works...

@greenape greenape added the bug Something isn't working label Apr 1, 2020
@jc-harrison
Copy link
Member

jc-harrison commented Apr 1, 2020

Ah, you're right. extract('week' FROM calls.call_date) is valid in PostgreSQL, but is not in the SQL standard. We should either find a form that's valid in all flavours of SQL, or document alternatives for the most common flavours.

From a quick search:

  • MySQL: extract(week FROM calls.call_date) (without quotes)
  • Oracle: extract(calls.call_date, week)
  • SQL Server: datepart(week, calls.call_date)
  • Spark: weekofyear(calls.call_date)
  • SQLite: cast(strftime('%W', calls.call_date) AS NUMERIC)

extract(week FROM calls.call_date) (without quotes) is also valid in PostgreSQL, so perhaps we should at least make that change so it's compatible with more (if not all) SQL flavours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants