ALTER SEMANTIC VIEW

Renames an existing semantic view. The view definition, including all tables, relationships, dimensions, metrics, and facts, is preserved under the new name. Queries using the old name will fail after the rename.

Note

ALTER SEMANTIC VIEW only supports the RENAME TO operation. For other operations use CREATE OR REPLACE SEMANTIC VIEW ....

Syntax

ALTER SEMANTIC VIEW [ IF EXISTS ] <name> RENAME TO <new_name>

Statement Variants

ALTER SEMANTIC VIEW <name> RENAME TO <new_name>

Renames the semantic view from <name> to <new_name>. Returns an error if <name> does not exist or if <new_name> already exists.

ALTER SEMANTIC VIEW IF EXISTS <name> RENAME TO <new_name>

Renames the semantic view if it exists. If <name> does not exist, the statement succeeds silently without modifying anything. Returns an error if <new_name> already exists.

Parameters

<name>

The current name of the semantic view to rename.

<new_name>

The new name for the semantic view. Must not match the name of an existing semantic view.

Output Columns

Returns a single row with 2 columns:

Column

Type

Description

old_name

VARCHAR

The original semantic view name before the rename.

new_name

VARCHAR

The new semantic view name after the rename.

Examples

Rename a semantic view:

ALTER SEMANTIC VIEW sales_view RENAME TO revenue_view;

After the rename, queries must use the new name:

-- This works
SELECT * FROM semantic_view('revenue_view',
    dimensions := ['region'],
    metrics := ['total_amount']
);

-- This fails: "semantic view 'sales_view' does not exist"
SELECT * FROM semantic_view('sales_view',
    dimensions := ['region'],
    metrics := ['total_amount']
);

Rename with IF EXISTS (safe no-op):

-- Succeeds silently if 'old_reports' does not exist
ALTER SEMANTIC VIEW IF EXISTS old_reports RENAME TO new_reports;

Error: target name already exists:

-- Assuming both 'sales' and 'inventory' exist
ALTER SEMANTIC VIEW sales RENAME TO inventory;
Error: semantic view 'inventory' already exists

The statement is case-insensitive:

alter semantic view sales_view rename to revenue_view;