Snowflake Semantic Views: Metrics as Database Objects
Define metrics once in a Snowflake semantic view, query them with plain SQL or Cortex Analyst, and add materializations without forking definitions.
By Dinesh ChandraSenior Data and AI Engineer · SnowPro certified- 1.A semantic view is a schema-level object that holds tables, relationships, facts, dimensions and metrics. Metrics live in the database, not in each BI tool.
- 2.Query it with the SEMANTIC_VIEW clause or, since March 2026, with standard SELECT and AGG() against the view name.
- 3.Readers need SELECT on the semantic view, not on the underlying tables.
- 4.Materializations went GA in November 2026. Use CREATE OR ALTER, never CREATE OR REPLACE, once they exist.
- 5.Many-to-many relationships, level of detail expressions and range joins are still in preview. Keep them out of production views.
Table of contents
- The problem
- The common wrong approach
- The approach that works
- Step 1: create the semantic view
- Step 2: check which dimensions a metric supports
- Step 3: query with the SEMANTIC_VIEW clause
- Step 4: query with standard SQL
- Step 5: grant it like a product
- Step 6: move existing YAML into the database
- Step 7: add a materialization for hot queries
- Edge cases and changes
- Trade-offs
- Pitfalls
- FAQ
- Is a semantic view a replacement for a regular view?
- Do analysts need access to the base tables?
- Can Cortex Analyst use a semantic view instead of a YAML file on a stage?
- Can I manage semantic views as code?
- What do materializations cost?
- What this means for your pipelines
Every company has three definitions of revenue: the one in the
finance dashboard, the one in the product dashboard, and the one an
analyst wrote in a notebook last quarter. Each is a SUM with a
slightly different filter, and nobody can say which one is right.
Snowflake semantic views put the definition in the database. A semantic view is a schema-level object that declares logical tables, how they join, and which facts, dimensions and metrics exist. BI tools, SQL users, Cortex Analyst and Cortex Agents all query the same object, so the metric is defined once and reviewed once.
This post builds one on the TPC-H sample data you already have, queries it two ways, grants it, and adds a materialization. If you already wrote Cortex Analyst YAML, the Cortex Analyst and Search post explains why that file matters; here you turn it into a governed database object.
The problem
Metric logic usually lives in the consuming tool. The BI semantic
model has one version, a dbt-built mart has another grain, and a
CREATE VIEW with a hard-coded GROUP BY serves a third dashboard.
When finance changes “net revenue” to exclude tax, you find out which
copies exist by waiting for someone to notice a mismatch.
Semantic views give Snowflake its own semantic layer. Defining them has
been generally available since mid-2025, querying through the
SEMANTIC_VIEW clause since August 2025, and querying with standard
SQL clauses since March 2, 2026. Semantic view materializations moved
to general availability in November 2026.
The common wrong approach
The wrong approach is a wide “metrics view” per dashboard:
create or replace view analytics.marts.revenue_by_segment as
select
c.c_mktsegment,
year(o.o_orderdate) as order_year,
sum(l.l_extendedprice * (1 - l.l_discount)) as net_revenue
from snowflake_sample_data.tpch_sf1.lineitem l
join snowflake_sample_data.tpch_sf1.orders o on o.o_orderkey = l.l_orderkey
join snowflake_sample_data.tpch_sf1.customer c on c.c_custkey = o.o_custkey
group by 1, 2;
It works until someone needs revenue by month instead of year. Then a second view appears, with the formula copied. Ten views later, the formula has drifted. A plain view fixes the grain at creation; a semantic view fixes the definition and lets the query choose the grain.
The approach that works
Step 1: create the semantic view
You need CREATE SEMANTIC VIEW on the target schema, USAGE on its
database and schema, and SELECT on the underlying tables. The
FACTS clause must come before DIMENSIONS.
create or replace semantic view analytics.semantic.sales_sv
tables (
orders as snowflake_sample_data.tpch_sf1.orders
primary key (o_orderkey)
comment = 'One row per order',
customers as snowflake_sample_data.tpch_sf1.customer
primary key (c_custkey)
comment = 'One row per customer',
line_items as snowflake_sample_data.tpch_sf1.lineitem
primary key (l_orderkey, l_linenumber)
comment = 'One row per order line'
)
relationships (
orders_to_customers as
orders (o_custkey) references customers,
line_items_to_orders as
line_items (l_orderkey) references orders
)
facts (
line_items.net_price as l_extendedprice * (1 - l_discount)
comment = 'Line price after discount'
)
dimensions (
customers.market_segment as customers.c_mktsegment
with synonyms = ('segment', 'customer segment')
comment = 'Customer market segment',
orders.order_date as o_orderdate
comment = 'Date the order was placed',
orders.order_year as year(o_orderdate)
comment = 'Calendar year of the order'
)
metrics (
line_items.net_revenue as sum(line_items.net_price)
comment = 'Revenue after discount, before tax',
orders.order_count as count(o_orderkey)
comment = 'Number of orders',
orders.average_order_value as avg(orders.o_totalprice)
comment = 'Average order total'
)
comment = 'Sales metrics for finance and BI. Owner: data platform.';
Facts are row-level expressions. Dimensions are what you group and filter by. Metrics are aggregations. Relationships tell Snowflake how to join, so a query never repeats the join logic. Comments and synonyms are not decoration: Cortex Analyst reads them when it turns a question into SQL.
Step 2: check which dimensions a metric supports
A dimension used with a metric must come from a related logical table at the same or a lower granularity. Ask Snowflake instead of guessing:
show semantic dimensions in analytics.semantic.sales_sv
for metric net_revenue;
Step 3: query with the SEMANTIC_VIEW clause
Name the metrics and dimensions you want. The WHERE goes inside the
parentheses and is applied before the metrics are computed:
select *
from semantic_view(
analytics.semantic.sales_sv
metrics line_items.net_revenue, orders.order_count
dimensions customers.market_segment as segment, orders.order_year as yr
where orders.order_year >= 1997
)
order by segment, yr;
Output columns follow the order of the clauses. This form can be
combined with joins, CTEs, PIVOT and GROUP BY outside the clause.
Step 4: query with standard SQL
Since March 2026 you can put the semantic view in FROM. Metrics must
be wrapped in AGG(), and every dimension in the select list must be in
GROUP BY:
select
market_segment,
agg(net_revenue) as net_revenue,
agg(order_count) as orders
from analytics.semantic.sales_sv
where order_year >= 1997
group by market_segment
having agg(net_revenue) > 0
order by 2 desc;
This is the form BI tools and analysts find natural. It has limits:
no joins, window functions, QUALIFY, PIVOT or correlated subqueries
in that SELECT. WHERE takes dimensions and facts; HAVING takes
metrics. When you need a join, use the SEMANTIC_VIEW clause.
Step 5: grant it like a product
grant select on semantic view analytics.semantic.sales_sv to role bi_reader;
grant select on future semantic views in schema analytics.semantic to role bi_reader;
SELECT on the semantic view is enough to query it; the role does not
need SELECT on the base tables. Cortex Agents also require SELECT on
the view. That makes the semantic view a clean access boundary, so
design your RBAC around it. Pair it
with masking and row access policies
on the base tables where columns are sensitive.
Step 6: move existing YAML into the database
If you have Cortex Analyst semantic model YAML, validate it as a
semantic view without creating anything by passing TRUE as the third
argument, then run it again without that argument to create the view:
call system$create_semantic_view_from_yaml(
'analytics.semantic',
$$
name: sales_from_yaml
tables:
- name: orders
base_table:
database: snowflake_sample_data
schema: tpch_sf1
table: orders
primary_key:
columns: [o_orderkey]
dimensions:
- name: order_status
expr: o_orderstatus
data_type: varchar
$$,
true
);
Going the other way, SELECT SYSTEM$READ_YAML_FROM_SEMANTIC_VIEW('analytics.semantic.sales_sv');
returns the YAML for review or version control.
Step 7: add a materialization for hot queries
Materializations pre-aggregate dimensions and metrics you query often.
The planner rewrites semantic queries to the cheapest materialization
that covers them. First set MAX_STALENESS in seconds (minimum 120),
then add the materialization with its own refresh warehouse:
alter semantic view analytics.semantic.sales_sv set max_staleness = 7200;
alter semantic view analytics.semantic.sales_sv
add materialization revenue_by_segment_year
warehouse = semantic_refresh_wh
as
dimensions customers.market_segment, orders.order_year
metrics line_items.net_revenue, orders.order_count;
Leave average_order_value out: averages, COUNT DISTINCT, medians and
percentiles cannot be re-aggregated from a materialization. The refresh
warehouse pays for background refreshes, so size it like any refresh
warehouse: small, dedicated, auto-suspend at 60 seconds.
Edge cases and changes
- CREATE OR REPLACE drops materializations. Once a view has them,
change it with
CREATE OR ALTER SEMANTIC VIEW, which needsOWNERSHIPand unsets any property you omit. - Not every query benefits. Rewrites apply to semantic SQL. Queries from Cortex Analyst and Cortex Agents that run physical SQL against the base tables do not use materializations. Masking or row access policies on referenced columns also prevent rewrites.
- Stale is skipped, not served. If refreshes fall behind
MAX_STALENESS, the materialization is not used. Failed refreshes suspend it until you resume it. - Clones and replicas. Cloned materializations start suspended; replicated ones must refresh in the target account before use. See zero-copy clones.
- Preview features. Range joins (
ASOF,BETWEEN),USINGrelationship selection, level of detail expressions and many-to-many relationships are preview as of November 2026. - Metadata hygiene. The docs warn against putting personal or regulated data in comments, synonyms and other metadata.
Trade-offs
A semantic view gives you one definition, one grant and one place for Cortex Analyst to read. You give up some SQL freedom: the standard-SQL form forbids joins and window functions, and every new metric is a DDL change instead of an analyst’s quick edit. That is the point, but plan a review path so the view does not become a bottleneck.
It is also Snowflake-specific. If you serve metrics to several engines, a tool-neutral semantic layer may still be the system of record, with semantic views generated from it. If Snowflake is where everyone queries, semantic views remove a moving part.
Pitfalls
- Metrics defined on the wrong table. Fix: attach each metric to
the logical table at its natural grain and check with
SHOW SEMANTIC DIMENSIONS ... FOR METRIC. - Missing primary keys. Fix: declare
PRIMARY KEYon every logical table so relationships and granularity resolve. - CREATE OR REPLACE in a deploy script. Fix: switch to
CREATE OR ALTERbefore you add the first materialization. - Materializing non-additive metrics. Fix: materialize sums and counts; leave averages and distinct counts to the base tables.
- Empty comments. Fix: write a one-line business definition on every metric; Analyst and humans both read it.
FAQ
Is a semantic view a replacement for a regular view?
No. A regular view stores a query at a fixed grain. A semantic view stores definitions and lets each query pick its dimensions and metrics. Keep regular views for row-level reshaping; use semantic views for governed metrics.
Do analysts need access to the base tables?
No. SELECT on the semantic view is enough to query it. Creating or
replacing the view still requires SELECT on the underlying tables.
Can Cortex Analyst use a semantic view instead of a YAML file on a stage?
Yes. You name the semantic view in the Analyst REST API request, and Cortex Agents can use semantic views directly. Verified queries and instructions for SQL generation can live in the view itself.
Can I manage semantic views as code?
Yes. Keep the CREATE OR ALTER SEMANTIC VIEW statements in your
migration repository, or export YAML with
SYSTEM$READ_YAML_FROM_SEMANTIC_VIEW for review. Declarative
DEFINE SEMANTIC VIEW in DCM projects is also available.
What do materializations cost?
Background refreshes run on the warehouse you name in the
materialization, so they cost warehouse credits like any refresh job.
Narrow IMMUTABLE WHERE conditions reduce refresh work on history that
never changes.
What this means for your pipelines
Your marts stay where they are; the semantic view sits on top of them
and becomes the contract that dashboards, SQL users and AI assistants
share. Build one per business domain, declare keys and relationships,
write the definitions into comments, and grant SELECT on the view
instead of the tables.
Add materializations only after query history shows the same grain
being asked for repeatedly, and change the view with CREATE OR ALTER
from that day on. One definition of revenue is worth more than any
dashboard built on three.
Sources: Semantic views overview, CREATE SEMANTIC VIEW, Querying semantic views, SEMANTIC_VIEW construct, SQL commands and privileges for semantic views, SHOW SEMANTIC DIMENSIONS FOR METRIC, Materializations, ALTER SEMANTIC VIEW, Standard SQL querying GA, 2026 feature updates.
Senior Data & AI Engineer · SnowPro Core & Gen AI Certified
4+ years building production data platforms on Snowflake, Databricks, AWS, and Azure. I write from hands-on experience with Medallion architectures, dbt, Airflow, PySpark, and Snowflake Cortex AI. Every tutorial on this blog reflects real pipeline decisions, not documentation rewrites.
Read more about the author →