Dataform query error: Invalid reference to script variable when creating a view

Hi there,

I found that variable declaration works in pre_operations{} when config { type: ‘table’ }, but if I change the type to view, I get the titular error. This is a reproducible error:

config {
    type: 'view'
}
pre_operations {
    DECLARE v_min_date DATE DEFAULT DATE_TRUNC(DATE_SUB(CURRENT_DATE, INTERVAL 24 MONTH), MONTH);
}

WITH
foo AS (
    SELECT v_min_date AS bar
)

SELECT * FROM foo

Is this a bug or am I doing something wrong?

1 Like

Short answer: I was wrong.

Variables cannot be declared for views, so in cases like these, it’s easier to either stick to tables or not abstract the variable