Variable cannot be no longer part of string - Postgres, metabase .46

Hi,
Yesterday we upgraded to newest version of metabase and some of our dashboards stopped to work. I have an SQL query to filter previous days in postgres. It was set to variable contains number. Where clause looked like that:

WHERE ("source"."Datetime" >= date_trunc('day', (now() + (INTERVAL '-{{number}} days'))))

The input for variable is created, but somehow will not insert it value into query, as it returns empty results The column index is out of range: 1, number of columns: 0.

The same equivalent without variables though returns result
WHERE ("source"."Datetime" >= date_trunc('day', (now() + (INTERVAL '-1 days'))))

I have also tried using concat(), or || to join '-' {{number}} 'days', but none of the options worked for me.

Is there a new way how to do what my previous variable filter did, or is it an unintended bug?

Can't you do something like this:

(now() - ({{num_of_days}} || ' days')::interval)

1 Like

I am also facing this same issue.

After updating to v0.46, SQL queries with variables in column names stopped working.

In our cenario, I used to have a variable {{default_days}} that was used in the query to define whether table column default_d1 or default_d15 should be used

I used it as follows, and it worked just fine

select
default_d{{default_days}}
from default

Now, after updating to v0.46, I get the error

ERROR: column "default_d$2" does not exist

Funny thing is, when I select the variable by itself, it returns the value it is set to.
select {{default_days}} returns '1' or '15' depending on what is inputed to the filter.

I'm not sure but I think this might have been caused by changes made to the variables. In v0.46, there were changes to make it possible to create a custom list for a dropdown text variable, for instance.

@Nellia I thought it was worth reporting this as a bug.

That works. Thank you! :slight_smile:

1 Like

Posting this here as I answered in your thread as well Support dynamic column selection via template tags · Issue #29810 · metabase/metabase · GitHub

Unfortunately this doesnt work for Snowflake. Though it seems to work for postgres. Does anyone have a solution for Snowflake?
I get this error:

SQL compilation error: syntax error line 2 at position 56 unexpected ')'.

Hi, I just updated to 46.0 and all my postgres dashboards stopped worked. I found this to work ---

WHERE your_date_column >= CAST((CURRENT_DATE - {{INTERVAL}}::INT)AS DATE)

the ' ' quotes should not be there and the interval is set to TEXT not number, and it works. Hopefully this helps someone!

v46.2 has been released and this was fixed