Snowflake DDL reordering tool
The GET_DDL function in Snowflake has one feature that does not allow using the result of its work as intended: objects are sorted alphabetically.
For example:
CREATE TABLE B (ID INT PRIMARY KEY);
CREATE TABLE A (ID INT REFERENCES B (ID));
SELECT GET_DDL ('DATABASE', 'TEST', TRUE);
will return
create or replace TABLE TEST.PUBLIC.A (
ID NUMBER (38,0),
foreign key (ID) references TEST.PUBLIC.B (ID)
);
create or replace TABLE TEST.PUBLIC.B (
ID NUMBER (38,0) NOT NULL,
primary key (ID)
);
Such DDL script could not be executed due to the wrong order of the objects.
This tool that will reorder objects based on their relatedness.
Applicable to all Snowflake objects (including VIEW), supports CREATE and ALTER, and respects FOREIGN KEYS, CLONE, SELECT AS, and other kinds of dependencies. Knows how to identify cyclical dependencies.
This tool also available to use in our API: https://docs.parsers.dev/#snowflake-get_ddl-function-result-reorder
Insert GET_DDL function result here:* set use_fully_qualified_names_for_recreated_objects
to TRUE