prql icon indicating copy to clipboard operation
prql copied to clipboard

Intervals broken for Postgres

Open mklopets opened this issue 2 years ago • 1 comments

prql dialect:postgres

from account
select [day_after_creation = created_at + 1days]

Postgres seems to require quotes around intervals:

SELECT
-  created_at + INTERVAL 1 DAY AS day_after_creation <--------- current output, will fail in postgres
+  created_at + 'INTERVAL 1 DAY' AS day_after_creation
FROM
  account

Error thrown:

Query 1 ERROR: ERROR:  syntax error at or near "1"
LINE 2:   created_at + INTERVAL 1 DAY AS day_after_creation
                                ^

mklopets avatar Dec 11 '22 12:12 mklopets

Ah, interesting. It looks like BQ doesn't: https://cloud.google.com/bigquery/docs/reference/standard-sql/interval_functions

Do you happen to know how common this is? I'd be happy to implement this if we had an idea of which dialects should do which.

max-sixty avatar Dec 11 '22 19:12 max-sixty

Unfortunately I don't have much experience with different dialects handling this. It looks like BigQuery and MySQL require no quotes, and Postgres requires one of the following two:

select now() + interval '1 month';
select now() + interval '1' month;

mklopets avatar Jan 25 '23 14:01 mklopets

Closed by https://github.com/PRQL/prql/pull/1649. If other dialects have other formats which aren't covered, let's reopen

max-sixty avatar Jan 31 '23 22:01 max-sixty