Functions¶
Loading the extension registers 20 SQL functions (19 names; get_ddl has two overloads). Most day-to-day work goes through the statements – CREATE, SHOW, DESCRIBE – and two query functions. This page lists every registered function, says which ones to call directly and which ones back a statement, and shows how a tool or agent can read their descriptions, parameters, and examples over SQL.
Function Inventory¶
Call these directly:
Function |
Type |
Purpose |
|---|---|---|
table |
Query a semantic view: returns the requested dimensions, metrics, or facts. |
|
table |
Show the SQL and query plan |
|
scalar |
Return the |
|
get_ddl(object_type, object_name, use_fully_qualified_names) |
scalar |
As above, with the view name schema-qualified in the output when the third argument is |
scalar |
Return a stored view’s definition as YAML, ready to re-import with |
These back a statement – use the statement instead:
Function |
Type |
Statement to use |
|---|---|---|
|
table |
|
|
table |
|
|
table |
|
|
table |
|
|
table |
|
|
table |
SHOW SEMANTIC DIMENSIONS (without |
|
table |
|
|
table |
|
|
table |
SHOW SEMANTIC FACTS (without |
|
table |
|
|
table |
SHOW SEMANTIC MATERIALIZATIONS (without |
|
table |
|
|
table |
SHOW SEMANTIC METRICS (without |
Internal – do not call:
Function |
Type |
Notes |
|---|---|---|
|
table |
Used by CREATE SEMANTIC VIEW to check that every member binds. Not part of the supported interface; its parameters and behavior can change in any release. |
|
table |
Used by CREATE SEMANTIC VIEW … FROM YAML FILE. Not part of the supported interface; its parameters and behavior can change in any release. |
The statements are the stable interface. The functions behind them are listed here so that a tool reading duckdb_functions() can tell what each one is; their descriptions say which statement to use.
Discovering Functions over SQL¶
Added in version 0.13.0.
Every function the extension registers has an entry in DuckDB’s duckdb_functions() table function, with a description and its real parameter names and types. Every function except the internal helpers also carries at least one runnable example. A tool or agent connected over SQL can learn the whole surface from there.
DuckDB 2.0’s duckdb_functions() has an extension_name column, but it is NULL for this extension’s functions. Filter on the categories column instead: every function this extension registers carries the semantic_views category, and no built-in DuckDB function does.
SELECT DISTINCT function_name, function_type, categories[2] AS kind
FROM duckdb_functions()
WHERE list_contains(categories, 'semantic_views')
ORDER BY kind DESC, function_name;
┌─────────────────────────────────────┬───────────────┬──────────┐
│ function_name │ function_type │ kind │
├─────────────────────────────────────┼───────────────┼──────────┤
│ explain_semantic_view │ table │ query │
│ semantic_view │ table │ query │
│ describe_semantic_view │ table │ metadata │
│ get_ddl │ scalar │ metadata │
│ list_semantic_views │ table │ metadata │
│ list_terse_semantic_views │ table │ metadata │
│ read_yaml_from_semantic_view │ scalar │ metadata │
│ show_columns_in_semantic_view │ table │ metadata │
│ show_semantic_dimensions │ table │ metadata │
│ show_semantic_dimensions_all │ table │ metadata │
│ show_semantic_dimensions_for_metric │ table │ metadata │
│ show_semantic_facts │ table │ metadata │
│ show_semantic_facts_all │ table │ metadata │
│ show_semantic_materializations │ table │ metadata │
│ show_semantic_materializations_all │ table │ metadata │
│ show_semantic_metrics │ table │ metadata │
│ show_semantic_metrics_all │ table │ metadata │
│ __sv_check_create │ table │ internal │
│ __sv_compute_create_from_yaml │ table │ internal │
└─────────────────────────────────────┴───────────────┴──────────┘
DISTINCT folds the two get_ddl overloads into one row; without it the query returns 20 rows, one per overload.
The columns a tool needs:
Column |
Type |
What it holds for this extension’s functions |
|---|---|---|
|
VARCHAR |
The name to call. |
|
VARCHAR |
|
|
VARCHAR[] |
|
|
VARCHAR |
What the function does. For a function that backs a statement, the description names the statement to use instead. |
|
VARCHAR[] |
Parameter names. For a table function, the positional arguments come first, in call order, and everything after them is a named parameter, passed as |
|
VARCHAR[] |
The DuckDB type of each parameter, in the same order as |
|
VARCHAR |
The result type of a scalar function ( |
|
VARCHAR[] |
Runnable SQL. For a function that backs a statement, the example is the statement itself. |
The internal column is true for every function the extension registers, and for DuckDB’s own built-in functions too, so it does not pick out the internal helpers. Use the internal category for that.
Read one function’s signature, description, and example:
SELECT unnest(parameters) AS parameter, unnest(parameter_types) AS type
FROM duckdb_functions()
WHERE function_name = 'semantic_view';
┌──────────────┬───────────┐
│ parameter │ type │
├──────────────┼───────────┤
│ view_name │ VARCHAR │
│ dimensions │ VARCHAR[] │
│ metrics │ VARCHAR[] │
│ facts │ VARCHAR[] │
│ where_clause │ VARCHAR │
│ column_order │ VARCHAR[] │
│ search_path │ VARCHAR[] │
└──────────────┴───────────┘
SELECT description, examples
FROM duckdb_functions()
WHERE function_name = 'semantic_view';
description = Queries a semantic view: returns the requested dimensions,
metrics and/or facts, generating the joins and GROUP BY from
the view definition. Pass at least one of dimensions, metrics
or facts; an item may name its column ('region AS r').
where_clause filters rows before aggregation, and
column_order (e.g. ['metrics', 'dimensions']) sets the order
of the columns. The SEMANTIC_VIEW(...) construct is the same
query written as SQL. The search_path parameter is reserved
(kept so views stored by earlier releases still bind); do not
pass it.
examples = [SELECT * FROM semantic_view('sales', dimensions := ['region'],
metrics := ['revenue']);]
The example assumes a view named sales with a region dimension and a revenue metric. The output above is shown one column per line and wrapped to fit.
A function that backs a statement points at the statement:
SELECT description, examples
FROM duckdb_functions()
WHERE function_name = 'show_semantic_metrics';
description = Backs SHOW SEMANTIC METRICS IN <view>: lists the metrics of one
semantic view. Use that statement rather than calling this
directly. The search_path parameter is reserved (kept so
views stored by earlier releases still bind); do not pass it.
examples = [SHOW SEMANTIC METRICS IN sales;]
Tip
A tool that starts knowing only the extension’s name can learn the function surface from duckdb_functions() as above, list the views with SHOW SEMANTIC VIEWS, list a view’s queryable members with SHOW COLUMNS IN SEMANTIC VIEW, check which dimensions are safe with a metric with SHOW SEMANTIC DIMENSIONS … FOR METRIC, and then query with semantic_view().
The search_path Parameter¶
Every table function the extension registers has a named parameter called search_path (type VARCHAR[]). It is reserved: each function reads the session’s search_path itself, so an unqualified view name resolves the way an unqualified table name does, and the parameter is kept only so that views stored by releases before 0.16.0, whose SQL text carries it, still bind. Do not pass it yourself. To control which schema an unqualified name resolves to, set DuckDB’s search_path setting, or qualify the view name ('analytics.sales'). See CREATE SEMANTIC VIEW for the resolution rule.
The scalar functions (get_ddl and read_yaml_from_semantic_view) have no search_path parameter; they read the session’s path the same way (see How an Unqualified Name Resolves).
Statements as Subqueries¶
Changed in version 0.16.0: SHOW SEMANTIC ... and DESCRIBE SEMANTIC VIEW can be used as
subqueries. Earlier releases refused them there with a parser error.
SHOW SEMANTIC ..., SHOW COLUMNS IN SEMANTIC VIEW and DESCRIBE SEMANTIC VIEW are queries, like DuckDB’s own SHOW and DESCRIBE, so you can use them wherever DuckDB accepts a query: in FROM, in a WITH clause or in a view body. That lets you filter, join and aggregate what they return:
SELECT DISTINCT object_name FROM (DESCRIBE SEMANTIC VIEW sales) WHERE object_kind = 'METRIC';
CREATE, DROP and ALTER SEMANTIC VIEW are statements, not queries, so they can’t appear inside one.
The GET_DDL recipe for dumping every view reads from (SHOW SEMANTIC VIEWS) this way.