How to represent table generating functions? #1333
-
Hi all, i'm trying to convert the following snippet for generating a series of weeks into PRQL (postgres dialect) with relevant_weeks as (
select date(dt) week from generate_series('2022-06-03', date(date_trunc('week', current_date)) + 4, '1 week') as dt
), With my first try, I ran into the following errors:
Error: ╭─[:7:9] │ 7 │ from (weeks_between @2022-06-03 (current_week + 4)) · ──────┬────── · ╰──────── expected a function, but found `default_db.weeks_between` ───╯ How can I resolve this error? What is the best way to represent this sequence? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
But if you remove it, PRQL gives an error:
... which is a limitation we no longer need, so I just removed it. Your query should now work, if you also prepend prql sql_dialect:postgres
func weeks_between start end -> s"SELECT generate_series({start}, {end}, '1 week') as date"
func current_week -> s"date(date_trunc('week', current_date))"
table relevant_weeks = (
weeks_between @2022-06-03 (current_week + 4)
select date
)
from relevant_weeks |
Beta Was this translation helpful? Give feedback.
from
is meant for pulling data from tables it's actually not needed in your case.But if you remove it, PRQL gives an error:
... which is a limitation we no longer need, so I just removed it.
Your query should now work, if you also prepend
generate_series
withSELECT
(this is current implementation limitation):