GET_DDL
functionsupportedDatabases & schemasReturns a DDL statement that can be used to recreate the specified object. For databases and schemas, GET_DDL is recursive (that is, it returns the DDL statements for recreating all supported objects within the specified database/schema). GET_DDL currently supports the following object types: - Cortex Agents (see CREATE AGENT) - Cortex Search services (see CREATE CORTEX SEARCH SERVICE) - MCP servers (see CREATE MCP SERVER) - Alerts (see CREATE ALERT) - Databases (see CREATE DATABASE), including catalog-linked databases. - Data metric functions (see CREATE DATA METRIC FUNCTION) - Contacts (see CREATE CONTACT) - dbt project objects (see CREATE DBT PROJECT) - Dynamic tables (see CREATE DYNAMIC TABLE) - Event tables (see CREATE EVENT TABLE) - External tables (see CREATE EXTERNAL TABLE) - Failover groups (see CREATE FAILOVER GROUP) - File formats (see CREATE FILE FORMAT) - Hybrid tables (see CREATE HYBRID TABLE) - Apache Iceberg™ tables (see CREATE ICEBERG TABLE) - Notebooks (see CREATE NOTEBOOK) - Online feature tables (see CREATE ONLINE FEATURE TABLE) - Openflow deployments, runtimes, and connectors (see CREATE OPENFLOW DEPLOYMENT, CREATE OPENFLOW RUNTIME, CREATE OPENFLOW CONNECTOR) - Pipes (see CREATE PIPE) - Policies (see CREATE AGGREGATION POLICY , CREATE AUTHENTICATION POLICY , CREATE DATA MOVEMENT POLICY , CREATE INGRESS POLICY , CREATE JOIN POLICY , CREATE MASKING POLICY , CREATE PASSWORD POLICY , CREATE PRIVACY POLICY , CREATE PROJECTION POLICY , CREATE ROW ACCESS POLICY , CREATE SESSION POLICY, CREATE STORAGE LIFECYCLE POLICY) - Data movement rules (see CREATE DATA MOVEMENT RULE) - Replication groups (see CREATE REPLICATION GROUP) - Schemas (see CREATE SCHEMA) - Semantic views (see CREATE SEMANTIC VIEW) - Sequences (see CREATE SEQUENCE) - Storage integrations (see CREATE STORAGE INTEGRATION) - Stored procedures (see CREATE PROCEDURE) - Streams (see CREATE STREAM) - Tables (see CREATE TABLE) - Tags (see CREATE TAG) - Tasks (see CREATE TASK) - UDFs, including external functions (see CREATE FUNCTION) - User-defined types (see CREATE TYPE) - Views (see CREATE VIEW) - Warehouses (see CREATE WAREHOUSE)
Syntax
supportedpartialnot supportednot scored
GET_DDL( '<object_type>' , '[<namespace>.]<object_name>' [ , <use_fully_qualified_names_for_recreated_objects> ] )
Parameters
| Name | Required | Description |
|---|---|---|
'object_type' | required | Specifies the type of object for which the DDL is returned. Valid values (corresponding to the supported object types) are: CORTEX_AGENT CORTEX_SEARCH_SERVICE CONTACT DATABASE DATA MOVEMENT RULE DYNAMIC_TABLE EVENT_TABLE FAILOVER_GROUP FILE_FORMAT FUNCTION (for UDFs, including data metric functions and external functions) ICEBERG_TABLE INTEGRATION (storage) MCP_SERVER PIPE POLICY (aggregation, authentication, data movement, ingress, join, masking, password, projection, row access, session, and storage lifecycle policies) PROCEDURE (for stored procedures) REPLICATION_GROUP SCHEMA SEMANTIC VIEW SEQUENCE STREAM TABLE (for tables, external tables, and hybrid tables) TAG (object tagging) TASK TYPE VIEW (for views and materialized views) WAREHOUSE |
'namespace.object_name' | required | Specifies the fully-qualified name of the object for which the DDL is returned. Namespace is the database and/or schema in which the object resides: Not used for databases. For schemas, takes the form of database. For schema objects (tables, views, streams, tasks, sequences, file formats, pipes, policies, and UDFs), takes the form of database.schema or schema. Namespace is optional if a database and schema are currently in use within the user session; otherwise, it is required. |
use_fully_qualified_names_for_recreated_objects | optional | If TRUE, the generated DDL statements use fully qualified names for the objects to be recreated. Default: FALSE. Note This does not affect the names of other objects referenced in the DDL statement (e.g. the name of a table referenced in a view definition). |
Returns
Returns a string (a VARCHAR value) containing the text of the DDL statement that created the object. For UDFs and stored procedures, the output might be slightly different from the original DDL. For example, if the UDF or stored procedure contains JavaScript code, the delimiter characters around the JavaScript code might be different. In addition, note that the DDL statement returned by the function might include default values for properties. For example, even if the original CREATE PROCEDURE statement did not specify EXECUTE AS OWNER, the DDL statement returned by the function includes EXECUTE AS OWNER, which is the default.
Usage notes
- The following notes apply to all supported objects:
- object_type and object_name (including namespace if specified) must be enclosed in single quotes.
- For object_type, TABLE and VIEW are interchangeable. If a TABLE object type is specified, and the object specified by name is a view, the function returns the DDL for the view and vice-versa.
- If object_type is FUNCTION (i.e. UDF) and the UDF has arguments, you must include the argument data types as part of the function name, in the form of 'function_name( [ arg_data_type [ , ... ] ] )', where function_name is the name of the function and arg_data_type is the data type of the argument.
- If object_type is PROCEDURE and the stored procedure has arguments, then you must include the argument data types as part of the function name, in the form of 'procedure_name( [ arg_data_type [ , ... ] ] )'.
- Querying this function for most Snowflake object types requires the same minimum permissions needed to view the object (using DESCRIBE <object> or SHOW <objects>). Snowflake restricts viewing special objects such as secure views to the owner, which is the role with the OWNERSHIP privilege on the object.
- When the returned DDL statement includes data type specifications, this function replaces data type aliases in the original statement with standard Snowflake data type names by default. If you want the returned DDL statement to include the data type aliases in the original statement, set the ENABLE_GET_DDL_USE_DATA_TYPE_ALIAS parameter to TRUE.
- For Iceberg tables:
- If you specify a TABLE object that’s an Iceberg table, the function returns the DDL for the Iceberg table.
- The output includes the ICEBERG_VERSION property for all Iceberg tables that are Snowflake-managed or part of a catalog-linked database, regardless of format version. For example, a v2 table includes ICEBERG_VERSION = 2 and a v3 table includes ICEBERG_VERSION = 3.
- If BASE_LOCATION was specified in the original CREATE ICEBERG TABLE statement, the function returns the original user input. Otherwise, the function returns the Snowflake-constructed file path (including the random 8-character string). For more information, see Data and metadata directories.
- For catalog-linked database:
- The output includes the LINKED_CATALOG options.
- For ALLOWED_NAMESPACES and BLOCKED_NAMESPACES, Snowflake doesn’t store nested namespaces if the set already contains the parent namespace. For example, if you create a database and specify ALLOWED_NAMESPACES = ('ns1', 'ns1.ns2', 'ns1.ns3'), Snowflake returns ALLOWED_NAMESPACES = ('ns1') in the GET_DDL output. The same applies for BLOCKED_NAMESPACES.
- The following notes are specific to view objects. The query result always:
- Returns lowercase SQL text for create or replace view, even if the casing in the original SQL statement used to create the view was uppercase or mixed case.
- Includes the OR REPLACE clause.
- Includes the SECURE property, if the view is secure.
- Excludes the COPY GRANTS view parameter, even if the original CREATE VIEW statement specifies the COPY GRANTS parameter.
- Generates the column list. If a masking policy is set on a column, the result specifies the masking policy for the column.
- Removes in-line SQL comments before the view body (that is, before AS). For example, in the following code, the comment immediately prior to the AS clause is removed: Copy code CREATE VIEW view_t1 -- GET_DDL() removes this comment. AS SELECT * FROM t1;
- The following notes apply specifically to table and view objects with a tag or policy:
- The role executing the GET_DDL query must have the global APPLY MASKING POLICY, APPLY ROW ACCESS POLICY, APPLY AGGREGATION POLICY, APPLY JOIN POLICY, APPLY PROJECTION POLICY, APPLY STORAGE LIFECYCLE POLICY, or APPLY TAG privilege and the USAGE privilege on the database and schema containing the policy or tag. Otherwise, Snowflake replaces the policy with #UNKNOWN_POLICY and the tag with #UNKNOWN_TAG='#UNKNOWN_VALUE. This text indicates that the column or the object is protected by a policy and a tag is set on the object or column. If this text is not removed prior to recreating the object, the CREATE OR REPLACE <object> statement fails. If this text is present in the GET_DDL query result, prior to recreating the object, consult with your internal governance administrator to determine which policies and tags are necessary for the columns or object. Finally, edit the GET_DDL query result and then recreate the object. Without the mentioned privileges, this table function does not return the corresponding row for the policy and tag assignments in the output of calling the function.
- When multiple tags are set on the object or column, the GET_DDL output sorts the tags alphabetically by tag name.
- Dropping a tag removes the tag from the GET_DDL output.
- If a tag is set on the table or view, the GET_DDL output for the table or view includes the tag assignments in the CREATE OR REPLACE statement.
- If a masking policy, row access policy, or storage lifecycle policy is set, the GET_DDL output includes the policy assignments using the WITH keyword.
- When a tag is set on the database or the schema, the GET_DDL output includes:
- An ALTER DATABASE statement when the tag is set on the database.
- An ALTER DATABASE statement and an ALTER SCHEMA statement when the tag is set on both the database and schema.
- An ALTER SCHEMA statement when the tag is set on the schema.
- A CREATE OR REPLACE statement to generate the tag, if the tag exists in the database or schema.
- The following apply to storage integrations:
- The command always returns the CREATE OR REPLACE STORAGE INTEGRATION syntax.
- If a STORAGE_AWS_EXTERNAL_ID was not specified during storage integration creation, this command returns the ID that was automatically generated during storage integration creation.
Access control requirements
- For semantic views, you must use a role that has been granted the REFERENCES or OWNERSHIP privilege on the semantic view.
Collation details
- Collation information is included in the input.