DESCRIBE SEMANTIC VIEW¶
Returns the definition of a semantic view as a multi-row result set in property-per-row format. Each row represents one property of one object (semantic view, table, relationship, variable, fact, dimension, metric, derived metric, or materialization) in the view definition.
Syntax¶
{ DESCRIBE | DESC } SEMANTIC VIEW <name>;
DESC is accepted as an abbreviation of DESCRIBE, matching Snowflake.
Parameters¶
<name>The name of the semantic view to describe. Returns an error if the view does not exist.
Note
DESCRIBE SEMANTIC VIEW runs in your transaction, so a CREATE / ALTER / DROP issued earlier in it is reflected here before you commit. See Reads Inside an Open Transaction See Your Changes.
Output Columns¶
The result contains multiple rows with 5 VARCHAR columns:
Column |
Type |
Description |
|---|---|---|
|
VARCHAR |
The type of object: |
|
VARCHAR |
The name of the object (table name, relationship name, variable name, fact/dimension/metric name, materialization name, verified query name). Empty string on the view-level rows and the |
|
VARCHAR |
The parent table for this object. Empty string for the view-level rows and for |
|
VARCHAR |
The property name being described. |
|
VARCHAR |
The property value. |
Object Kinds and Properties¶
Rows appear in definition order: the view-level comment, MAX_STALENESS and tags (when set), then TABLE objects, then RELATIONSHIP, VARIABLE, FACT, DIMENSION, METRIC, DERIVED_METRIC, MATERIALIZATION, CUSTOM_INSTRUCTIONS, and AI_VERIFIED_QUERY.
Changed in version 0.14.0: The DATA_TYPE property rows carry each member’s type again. They had been
empty for every view created since v0.10.0. The type is now worked out when
the command runs, so views created in that window report it too, with no
need to re-create them.
- View-level comment, MAX_STALENESS and tags
Emitted only when a view-level comment (in
CREATEor via ALTER SEMANTIC VIEW SET COMMENT),MAX_STALENESSor view-level tags are set. The rows describe the view itself, soobject_kind,object_name, andparent_entityare all empty strings. Produces up to three property rows:Property
Description
COMMENTThe view-level comment text.
MAX_STALENESSThe view’s MAX_STALENESS as written: a number of seconds (
3600) or an interval (1 hour).Added in version 0.18.0.
TAGSThe view’s tags as a JSON object. See
TAGSbelow.- TABLE
One block per table declared in the
TABLESclause, named by its physical table, or by its alias for a table defined by a query. Each table produces 1-7 property rows:Property
Description
BASE_TABLE_DATABASE_NAMEThe DuckDB database containing the physical table (e.g.,
memory).BASE_TABLE_SCHEMA_NAMEThe DuckDB schema containing the physical table (e.g.,
main).BASE_TABLE_NAMEThe physical table name.
DEFINITIONFor a table defined by a query, the query, without its parentheses. Such a table has no
BASE_TABLE_*rows, as in Snowflake.Added in version 0.18.0.
PRIMARY_KEYJSON array of primary key column names (e.g.,
["id"]). Only emitted when a primary key is declared.COMMENTThe table comment text. Only emitted when a comment is set.
SYNONYMSJSON array of synonym strings (e.g.,
["transactions","purchases"]). Only emitted when synonyms are set.TAGSJSON object of the object’s tags, in declaration order (e.g.,
{"S_LAYER_KIND":"dimension","governance.pii":"none"}). Each key is the tag name asGET_DDLwrites it. Only emitted when tags are set.Added in version 0.17.0.
- RELATIONSHIP
One block per relationship declared in the
RELATIONSHIPSclause:Property
Description
TABLEThe physical table name on the foreign key side.
REF_TABLEThe physical table name on the referenced (primary key) side.
FOREIGN_KEYJSON array of foreign key column names (e.g.,
["customer_id"]).REF_KEYJSON array of referenced key column names (e.g.,
["id"]).- VARIABLE
Added in version 0.18.0.
One block per variable declared in the
VARIABLESclause (see VARIABLES), in declaration order, named byobject_name. Variables have an emptyparent_entity. Each property is emitted only when the variable has it; a variable with no type, default or comment produces oneDATA_TYPErow with an empty value:Property
Description
DATA_TYPEThe variable’s type as declared (e.g.,
INTEGER).DEFAULT_VALUEThe default expression as written (e.g.,
1000orcurrent_date). A default declared with:=is shown the same way.COMMENTThe variable’s comment text.
A member that reads a variable reports its
DATA_TYPEas if the variable were its default, or aNULLof the variable’s type when it has no default.- FACT
One block per fact declared in the
FACTSclause:Property
Description
TABLEThe physical table name the fact is scoped to.
EXPRESSIONThe row-level SQL expression defining the fact.
DATA_TYPEThe type the member’s column has in a semantic-view query, in DuckDB’s spelling (
VARCHAR,BIGINT,DECIMAL(38,2)). Determined when the command runs, so it follows the current source columns. Empty when the member’s source no longer binds (for example, its table was dropped), or when the member cannot be queried on its own because of a fan trap. See Reported Data Types.COMMENTThe fact comment text. Only emitted when a comment is set.
SYNONYMSJSON array of synonym strings. Only emitted when synonyms are set.
TAGSJSON object of the object’s tags, in declaration order (e.g.,
{"S_LAYER_KIND":"dimension","governance.pii":"none"}). Each key is the tag name asGET_DDLwrites it. Only emitted when tags are set.Added in version 0.17.0.
SAMPLE_VALUESJSON array of the fact’s sample values (e.g.,
["100","250"]). Only emitted when set.Added in version 0.18.0.
LABELS["FILTER"]when the fact is declared a named filter withLABELS = (FILTER). Only emitted when labeled.ACCESS_MODIFIERPUBLICorPRIVATE. Always emitted.- DIMENSION
One block per dimension declared in the
DIMENSIONSclause:Property
Description
TABLEThe physical table name the dimension is scoped to.
EXPRESSIONThe SQL expression defining the dimension.
DATA_TYPEThe type the member’s column has in a semantic-view query, in DuckDB’s spelling (
VARCHAR,BIGINT,DECIMAL(38,2)). Determined when the command runs, so it follows the current source columns. Empty when the member’s source no longer binds (for example, its table was dropped), or when the member cannot be queried on its own because of a fan trap. See Reported Data Types.COMMENTThe dimension comment text. Only emitted when a comment is set.
SYNONYMSJSON array of synonym strings. Only emitted when synonyms are set.
TAGSJSON object of the object’s tags, in declaration order (e.g.,
{"S_LAYER_KIND":"dimension","governance.pii":"none"}). Each key is the tag name asGET_DDLwrites it. Only emitted when tags are set.Added in version 0.17.0.
SAMPLE_VALUESJSON array of the dimension’s sample values (e.g.,
["East","West"]). Only emitted when set.Added in version 0.18.0.
IS_ENUMtruewhen the dimension is declaredIS_ENUM. Only emitted when set.Added in version 0.18.0.
CORTEX_SEARCH_SERVICE_COLUMN_NAME,CORTEX_SEARCH_SERVICE_DATABASE_NAME,CORTEX_SEARCH_SERVICE_SCHEMA_NAME,CORTEX_SEARCH_SERVICE_NAMEThe parts of the dimension’s
WITH CORTEX SEARCH SERVICEclause, as Snowflake names them: theUSINGcolumn, the database, the schema and the service. Only the parts written are emitted;CORTEX_SEARCH_SERVICE_NAMEalways is when the clause is present.Added in version 0.18.0.
LABELS["FILTER"]when the dimension is declared a named filter withLABELS = (FILTER). Only emitted when labeled.- METRIC
One block per base metric (those scoped to a table) declared in the
METRICSclause:Property
Description
TABLEThe physical table name the metric is scoped to.
EXPRESSIONThe aggregate SQL expression defining the metric.
DATA_TYPEThe type the member’s column has in a semantic-view query, in DuckDB’s spelling (
VARCHAR,BIGINT,DECIMAL(38,2)). Determined when the command runs, so it follows the current source columns. Empty when the member’s source no longer binds (for example, its table was dropped), or when the member cannot be queried on its own because of a fan trap. See Reported Data Types.COMMENTThe metric comment text. Only emitted when a comment is set.
SYNONYMSJSON array of synonym strings. Only emitted when synonyms are set.
TAGSJSON object of the object’s tags, in declaration order (e.g.,
{"S_LAYER_KIND":"dimension","governance.pii":"none"}). Each key is the tag name asGET_DDLwrites it. Only emitted when tags are set.Added in version 0.17.0.
ACCESS_MODIFIERPUBLICorPRIVATE. Always emitted.NON_ADDITIVE_BYComma-separated list of non-additive dimensions with optional sort/nulls (e.g.,
report_date DESC NULLS FIRST). Only emitted for semi-additive metrics.WINDOW_SPECReconstructed OVER clause string (e.g.,
AVG(total_qty) OVER (PARTITION BY EXCLUDING date ORDER BY date)). Only emitted for window metrics.- DERIVED_METRIC
One block per derived metric (those referencing other metrics rather than a table). Derived metrics have an empty
parent_entity:Property
Description
EXPRESSIONThe expression composing other metrics.
DATA_TYPEThe type the member’s column has in a semantic-view query, in DuckDB’s spelling (
VARCHAR,BIGINT,DECIMAL(38,2)). Determined when the command runs, so it follows the current source columns. Empty when the member’s source no longer binds (for example, its table was dropped), or when the member cannot be queried on its own because of a fan trap. See Reported Data Types.COMMENTThe derived metric comment text. Only emitted when a comment is set.
SYNONYMSJSON array of synonym strings. Only emitted when synonyms are set.
TAGSJSON object of the object’s tags, in declaration order (e.g.,
{"S_LAYER_KIND":"dimension","governance.pii":"none"}). Each key is the tag name asGET_DDLwrites it. Only emitted when tags are set.Added in version 0.17.0.
ACCESS_MODIFIERPUBLICorPRIVATE. Always emitted.
Note
Derived metrics never carry NON_ADDITIVE_BY or WINDOW_SPEC
properties: the parser rejects NON ADDITIVE BY and OVER on a derived
metric, so a semi-additive or window derived metric cannot be defined. Those
properties appear only under METRIC (base metrics scoped to a table).
- MATERIALIZATION
Added in version 0.7.0.
One block per materialization declared in the
MATERIALIZATIONSclause. Each materialization produces 3 property rows. Materializations have an emptyparent_entity:Property
Description
TABLEThe physical table name that the materialization points to.
DIMENSIONSJSON array of dimension names covered by this materialization (e.g.,
["region"]). Empty array[]when no dimensions are declared.METRICSJSON array of metric names covered by this materialization (e.g.,
["revenue","order_count"]). Empty array[]when no metrics are declared.- CUSTOM_INSTRUCTIONS
Added in version 0.18.0.
One row per Cortex Analyst instruction the view carries (see Cortex Analyst metadata), with empty
object_nameandparent_entity, as in Snowflake:Property
Description
AI_SQL_GENERATIONThe
AI_SQL_GENERATIONtext.AI_QUESTION_CATEGORIZATIONThe
AI_QUESTION_CATEGORIZATIONtext.- AI_VERIFIED_QUERY
Added in version 0.18.0.
One block per entry of
AI_VERIFIED_QUERIES, named byobject_name:Property
Description
QUESTIONThe question.
VERIFIED_ATSeconds since the Unix epoch. Only emitted when set.
ONBOARDING_QUESTIONtrueorfalse. Always emitted.VERIFIED_BYWho verified the query, as written. Only emitted when set.
SQLThe SQL text.
Examples¶
Simple single-table view:
CREATE SEMANTIC VIEW order_metrics AS
TABLES (
o AS orders PRIMARY KEY (id)
)
DIMENSIONS (
o.region AS o.region
)
METRICS (
o.total AS SUM(o.amount)
);
DESCRIBE SEMANTIC VIEW order_metrics;
┌─────────────┬─────────────┬───────────────┬──────────────────────────┬────────────────┐
│ object_kind │ object_name │ parent_entity │ property │ property_value │
├─────────────┼─────────────┼───────────────┼──────────────────────────┼────────────────┤
│ TABLE │ orders │ │ BASE_TABLE_DATABASE_NAME │ memory │
│ TABLE │ orders │ │ BASE_TABLE_SCHEMA_NAME │ main │
│ TABLE │ orders │ │ BASE_TABLE_NAME │ orders │
│ TABLE │ orders │ │ PRIMARY_KEY │ ["id"] │
│ DIMENSION │ region │ orders │ TABLE │ orders │
│ DIMENSION │ region │ orders │ EXPRESSION │ o.region │
│ DIMENSION │ region │ orders │ DATA_TYPE │ VARCHAR │
│ METRIC │ total │ orders │ TABLE │ orders │
│ METRIC │ total │ orders │ EXPRESSION │ SUM(o.amount) │
│ METRIC │ total │ orders │ DATA_TYPE │ DECIMAL(38,2) │
│ METRIC │ total │ orders │ ACCESS_MODIFIER │ PUBLIC │
└─────────────┴─────────────┴───────────────┴──────────────────────────┴────────────────┘
View with metadata annotations:
CREATE SEMANTIC VIEW annotated AS
TABLES (
o AS orders PRIMARY KEY (id) COMMENT = 'Order data'
)
DIMENSIONS (
o.region AS o.region COMMENT = 'Sales region' WITH SYNONYMS = ('territory')
)
METRICS (
o.revenue AS SUM(o.amount) COMMENT = 'Total revenue'
);
ALTER SEMANTIC VIEW annotated SET COMMENT = 'Revenue analytics';
DESCRIBE SEMANTIC VIEW annotated;
┌─────────────┬─────────────┬───────────────┬──────────────────────────┬───────────────────┐
│ object_kind │ object_name │ parent_entity │ property │ property_value │
├─────────────┼─────────────┼───────────────┼──────────────────────────┼───────────────────┤
│ │ │ │ COMMENT │ Revenue analytics │
│ TABLE │ orders │ │ BASE_TABLE_DATABASE_NAME │ memory │
│ TABLE │ orders │ │ BASE_TABLE_SCHEMA_NAME │ main │
│ TABLE │ orders │ │ BASE_TABLE_NAME │ orders │
│ TABLE │ orders │ │ PRIMARY_KEY │ ["id"] │
│ TABLE │ orders │ │ COMMENT │ Order data │
│ DIMENSION │ region │ orders │ TABLE │ orders │
│ DIMENSION │ region │ orders │ EXPRESSION │ o.region │
│ DIMENSION │ region │ orders │ DATA_TYPE │ VARCHAR │
│ DIMENSION │ region │ orders │ COMMENT │ Sales region │
│ DIMENSION │ region │ orders │ SYNONYMS │ ["territory"] │
│ METRIC │ revenue │ orders │ TABLE │ orders │
│ METRIC │ revenue │ orders │ EXPRESSION │ SUM(o.amount) │
│ METRIC │ revenue │ orders │ DATA_TYPE │ DECIMAL(38,2) │
│ METRIC │ revenue │ orders │ COMMENT │ Total revenue │
│ METRIC │ revenue │ orders │ ACCESS_MODIFIER │ PUBLIC │
└─────────────┴─────────────┴───────────────┴──────────────────────────┴───────────────────┘
The first row is the view-level comment, so its object_kind and object_name are empty.
View with materializations:
CREATE SEMANTIC VIEW order_metrics AS
TABLES (
o AS orders PRIMARY KEY (id)
)
DIMENSIONS (
o.region AS o.region
)
METRICS (
o.revenue AS SUM(o.amount),
o.order_count AS COUNT(*)
)
MATERIALIZATIONS (
region_agg AS (
TABLE revenue_by_region,
DIMENSIONS (region),
METRICS (revenue, order_count)
)
);
DESCRIBE SEMANTIC VIEW order_metrics;
┌─────────────────┬─────────────┬───────────────┬──────────────────────────┬───────────────────────────┐
│ object_kind │ object_name │ parent_entity │ property │ property_value │
├─────────────────┼─────────────┼───────────────┼──────────────────────────┼───────────────────────────┤
│ TABLE │ orders │ │ BASE_TABLE_DATABASE_NAME │ memory │
│ TABLE │ orders │ │ BASE_TABLE_SCHEMA_NAME │ main │
│ TABLE │ orders │ │ BASE_TABLE_NAME │ orders │
│ TABLE │ orders │ │ PRIMARY_KEY │ ["id"] │
│ DIMENSION │ region │ orders │ TABLE │ orders │
│ DIMENSION │ region │ orders │ EXPRESSION │ o.region │
│ DIMENSION │ region │ orders │ DATA_TYPE │ VARCHAR │
│ METRIC │ revenue │ orders │ TABLE │ orders │
│ METRIC │ revenue │ orders │ EXPRESSION │ SUM(o.amount) │
│ METRIC │ revenue │ orders │ DATA_TYPE │ DECIMAL(38,2) │
│ METRIC │ revenue │ orders │ ACCESS_MODIFIER │ PUBLIC │
│ METRIC │ order_count │ orders │ TABLE │ orders │
│ METRIC │ order_count │ orders │ EXPRESSION │ COUNT(*) │
│ METRIC │ order_count │ orders │ DATA_TYPE │ BIGINT │
│ METRIC │ order_count │ orders │ ACCESS_MODIFIER │ PUBLIC │
│ MATERIALIZATION │ region_agg │ │ TABLE │ revenue_by_region │
│ MATERIALIZATION │ region_agg │ │ DIMENSIONS │ ["region"] │
│ MATERIALIZATION │ region_agg │ │ METRICS │ ["revenue","order_count"] │
└─────────────────┴─────────────┴───────────────┴──────────────────────────┴───────────────────────────┘
The materialization rows come last, after the tables, dimensions, and metrics.
Filtering the output:
Added in version 0.16.0.
DESCRIBE SEMANTIC VIEW can be used as a subquery or in a WITH clause, like DuckDB’s own DESCRIBE (see Statements as Subqueries). Filter by object_kind to pick out one part of the definition. With the view above, only the materialization rows:
SELECT object_name, property, property_value
FROM (DESCRIBE SEMANTIC VIEW order_metrics)
WHERE object_kind = 'MATERIALIZATION';
┌─────────────┬────────────┬───────────────────────────┐
│ object_name │ property │ property_value │
├─────────────┼────────────┼───────────────────────────┤
│ region_agg │ TABLE │ revenue_by_region │
│ region_agg │ DIMENSIONS │ ["region"] │
│ region_agg │ METRICS │ ["revenue","order_count"] │
└─────────────┴────────────┴───────────────────────────┘
Only the dimensions:
SELECT object_name, property, property_value
FROM (DESCRIBE SEMANTIC VIEW order_metrics)
WHERE object_kind = 'DIMENSION';
┌─────────────┬────────────┬────────────────┐
│ object_name │ property │ property_value │
├─────────────┼────────────┼────────────────┤
│ region │ TABLE │ orders │
│ region │ EXPRESSION │ o.region │
│ region │ DATA_TYPE │ VARCHAR │
└─────────────┴────────────┴────────────────┘
How many objects of each kind the view declares:
SELECT object_kind, count(DISTINCT object_name) AS objects
FROM (DESCRIBE SEMANTIC VIEW order_metrics)
GROUP BY object_kind
ORDER BY object_kind;
┌─────────────────┬─────────┐
│ object_kind │ objects │
├─────────────────┼─────────┤
│ DIMENSION │ 1 │
│ MATERIALIZATION │ 1 │
│ METRIC │ 2 │
│ TABLE │ 1 │
└─────────────────┴─────────┘
The relationships of a view with more than one table:
CREATE SEMANTIC VIEW shop AS
TABLES (
o AS orders PRIMARY KEY (id),
c AS customers PRIMARY KEY (id)
)
RELATIONSHIPS (
order_customer AS o(customer_id) REFERENCES c
)
DIMENSIONS (
c.name AS c.name
)
METRICS (
o.revenue AS SUM(o.amount)
);
SELECT object_name, property, property_value
FROM (DESCRIBE SEMANTIC VIEW shop)
WHERE object_kind = 'RELATIONSHIP';
┌────────────────┬─────────────┬─────────────────┐
│ object_name │ property │ property_value │
├────────────────┼─────────────┼─────────────────┤
│ order_customer │ TABLE │ orders │
│ order_customer │ REF_TABLE │ customers │
│ order_customer │ FOREIGN_KEY │ ["customer_id"] │
│ order_customer │ REF_KEY │ ["id"] │
└────────────────┴─────────────┴─────────────────┘
The variables of the sales_analysis view from VARIABLES:
SELECT object_name, property, property_value
FROM (DESCRIBE SEMANTIC VIEW sales_analysis)
WHERE object_kind = 'VARIABLE';
┌───────────────┬───────────────┬─────────────────────────┐
│ object_name │ property │ property_value │
├───────────────┼───────────────┼─────────────────────────┤
│ min_amount │ DATA_TYPE │ INTEGER │
│ min_amount │ DEFAULT_VALUE │ 1000 │
│ multiplier │ DATA_TYPE │ DOUBLE │
│ multiplier │ DEFAULT_VALUE │ 1.0 │
│ target_region │ DATA_TYPE │ VARCHAR │
│ target_region │ COMMENT │ the region to report on │
└───────────────┴───────────────┴─────────────────────────┘
Error: view does not exist:
DESCRIBE SEMANTIC VIEW nonexistent_view;
Error: semantic view 'nonexistent_view' does not exist
The statement is case-insensitive:
describe semantic view order_metrics;