SEMANTIC_VIEW

constructsupportedQueries & DML

docs.snowflake.com ↗

Specifies the semantic view to query. You specify SEMANTIC_VIEW(…) in a FROM clause in a SELECT statement. Note You can’t query private facts or metrics or use them in the WHERE condition.

Syntax

supportedpartialnot supportednot scored

SEMANTIC_VIEW(
  [<namespace>.]<semantic_view_name>
  [
    {
      METRICS <metric_expr> [ [ AS ] <alias> ] [ , ... ] |
      FACTS <fact_expr>  [ , ... ]
    }
  ]
  [ DIMENSIONS <dimension_expr>  [ [ AS ] <alias> ] [ , ... ] ]
  [ WHERE <predicate> ]
)

Parameters

NameRequiredDescription
[namespace.]semantic_view_nameSpecifies the identifier for the semantic view to query. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive. For more information, see Identifier requirements.
METRICS metric_expr [ [ AS ] alias ] [ , ... ]Specifies the metrics that you want to return in the results. You can also specify an expression that includes: Scalar expressions that refer to metrics in the semantic view. Aggregations of dimensions or facts in the semantic view. Note You can’t specify private metrics. For the names of the metrics: You can qualify the name of the metric (for example, my_logical_table.my_metric). Using the unqualified name works only if there are no other identifiers with the same unqualified name in the semantic view. For example, if a metric and a dimension use the same unqualified name, you must qualify the name of the metric in the query. To specify all metrics in a logical table, use an asterisk as a wildcard, qualified by the logical table name (for example, my_logical_table.*). You can’t specify an asterisk without qualifying it with a table name. You can specify an alias for a metric after the name of the metric. You can use the optional AS keyword before the alias. Specify the metrics in the order in which they should appear in the results.
FACTS fact_expr [ , ... ]Specifies the facts that you want to return in the results. You can also specify scalar expressions that refer to facts or dimensions in the semantic view. If you specify a scalar expression, the dimensions and facts in that expression must belong to the same logical table. Note You can’t specify private facts. Unlike dimensions specified in the DIMENSIONS clause, the query does not group the facts specified in the FACTS clause. Different rows can include the same value for a fact. Specify the facts in the order in which they should appear in the results.
DIMENSIONS dimension_expr [ [ AS ] alias ] [ , ... ]Specifies the dimensions that you want to return in the results. You can also specify scalar expressions that refer to dimensions or facts in the semantic view. If you specify a scalar expression, the dimensions and facts in that expression must belong to the same logical table. The query groups the results by the dimensions that you specify here. For example, if a logical table includes five distinct values for a dimension, specifying that dimension in the DIMENSIONS clause returns five rows. For the names of the dimensions: You can qualify the name of the dimension (for example, my_logical_table.my_dimension). Using the unqualified name works only if there are no other identifiers with the same unqualified name in the semantic view. For example, if a metric and a dimension use the same unqualified name, you must qualify the name of the dimension in the query. To specify all dimensions in a logical table, use an asterisk as a wildcard, qualified by the logical table name (for example, my_logical_table.*). You can’t specify an asterisk without qualifying it with a table name. You can specify an alias for a dimension after the expression for the dimension. You can use the optional AS keyword before the alias. If you specify a scalar expression, you can’t refer to dimensions in other semantic views or metrics. Specify the dimensions in the order in which they should appear in the results. Note If you are returning a window function metric, you must also return the dimensions that are specified in PARTITION BY dimension, PARTITION BY EXCLUDING dimension, and ORDER BY dimension clauses in the CREATE SEMANTIC VIEW statement for that semantic view. See Defining and querying window function metrics.
WHERE predicateA boolean expression. The expression can include logical operators, built-in functions, and user-defined functions (UDFs). In the condition, you can only refer to dimensions, facts, and expressions that use dimensions and facts. If you specify facts from different entities, the RELATIONSHIPS clause in the semantic view definition must define a relationship between these entities. This filter condition is applied before the metrics are computed.

Usage notes

Parameters

[namespace.]semantic_view_name: Specifies the identifier for the semantic view to query. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive. For more information, see Identifier requirements. METRICS metric_expr [ [ AS ] alias ] [ , ... ]: Specifies the metrics that you want to return in the results. You can also specify an expression that includes: Scalar expressions that refer to metrics in the semantic view. Aggregations of dimensions or facts in the semantic view. Note You can’t specify private metrics. For the names of the metrics: You can qualify the name of the metric (for example, my_logical_table.my_metric). Using the unqualified name works only if there are no other identifiers with the same unqualified name in the semantic view. For example, if a metric and a dimension use the same unqualified name, you must qualify the name of the metric in the query. To specify all metrics in a logical table, use an asterisk as a wildcard, qualified by the logical table name (for example, my_logical_table.*). You can’t specify an asterisk without qualifying it with a table name. You can specify an alias for a metric after the name of the metric. You can use the optional AS keyword before the alias. Specify the metrics in the order in which they should appear in the results. FACTS fact_expr [ , ... ]: Specifies the facts that you want to return in the results. You can also specify scalar expressions that refer to facts or dimensions in the semantic view. If you specify a scalar expression, the dimensions and facts in that expression must belong to the same logical table. Note You can’t specify private facts. Unlike dimensions specified in the DIMENSIONS clause, the query does not group the facts specified in the FACTS clause. Different rows can include the same value for a fact. Specify the facts in the order in which they should appear in the results. DIMENSIONS dimension_expr [ [ AS ] alias ] [ , ... ]: Specifies the dimensions that you want to return in the results. You can also specify scalar expressions that refer to dimensions or facts in the semantic view. If you specify a scalar expression, the dimensions and facts in that expression must belong to the same logical table. The query groups the results by the dimensions that you specify here. For example, if a logical table includes five distinct values for a dimension, specifying that dimension in the DIMENSIONS clause returns five rows. For the names of the dimensions: You can qualify the name of the dimension (for example, my_logical_table.my_dimension). Using the unqualified name works only if there are no other identifiers with the same unqualified name in the semantic view. For example, if a metric and a dimension use the same unqualified name, you must qualify the name of the dimension in the query. To specify all dimensions in a logical table, use an asterisk as a wildcard, qualified by the logical table name (for example, my_logical_table.*). You can’t specify an asterisk without qualifying it with a table name. You can specify an alias for a dimension after the expression for the dimension. You can use the optional AS keyword before the alias. If you specify a scalar expression, you can’t refer to dimensions in other semantic views or metrics. Specify the dimensions in the order in which they should appear in the results. Note If you are returning a window function metric, you must also return the dimensions that are specified in PARTITION BY dimension, PARTITION BY EXCLUDING dimension, and ORDER BY dimension clauses in the CREATE SEMANTIC VIEW statement for that semantic view. See Defining and querying window function metrics. WHERE predicate: A boolean expression. The expression can include logical operators, built-in functions, and user-defined functions (UDFs). In the condition, you can only refer to dimensions, facts, and expressions that use dimensions and facts. If you specify facts from different entities, the RELATIONSHIPS clause in the semantic view definition must define a relationship between these entities. This filter condition is applied before the metrics are computed.

See also

Referenced by