Multiple Schemas with Shared Tables Can Use a Single View Accessed with Parameterized Table Names

Looker will not be updating this content, nor guarantees that everything is up-to-date. 

If you have multiple schemas with shared tables in your database, these shared tables can be represented by a single view file in Looker to prevent duplicate LookML.

But if you have a different model for each schema, how do you tell the shared view files to point to the appropriate schema/table for each model?

You do this using Liquid templates in the sql_table_name parameter. With Liquid, you can access the _model._name variable, which is the model name of the current Explore in the browser. Based on the model name, you can have sql_table_name return the appropriate schema.table like this:

view: table_name {
sql_table_name:
{% if _model._name == 'model_a' %}
schema_a.table_name
{% else %}
schema_b.table_name
{% endif %} ;;
}
Version history
Last update:
‎05-16-2022 10:40 AM
Updated by: