Passing schema as a variable

Hi there,

I'm looking forward to embed a dashboard in my web application. There, each client will have access to their data, and that data is split by schema in our database.

My goal was to pass the customer's schema and use it on the queries, like in the example below:

SELECT 
    count(*) AS "count"
FROM {{schema}}.users

But I'm getting the below error. Looks like there are a few CAST operations running on the variable.

image

I've tried the below approach as well, with no success.

SET search_path = {{schema}};
SELECT 
    count(*) AS "count"
FROM users

I wonder if it's possible to achieve what I'm trying to do using Metabase?

Thank you.

Hi @hsberlesi
It’s not possible to use the variables for that currently:
https://github.com/metabase/metabase/issues/4639 - upvote by clicking :+1: on the first post

1 Like

Thank you, @flamber!