Additionally, a couple other parts are partially supported, and require additional work to be implemented in order to properly emulate the original functionality. Specifically, we're talking about the MASKED WITH property, which will be covered in the patterns section of this page.
This pattern showcases the translation for MASKED WITH property. CREATE OR REPLACE MASKING POLICY is inserted somewhere before the first usage, and then referenced by a SET MASKING POLICY clause.
The name of the new MASKING POLICY will be the concatenation of the name and arguments of the original MASKED WITH FUNCTION, as seen below:
/*** MSC-INFORMATION - MSCINF0034 - MASKING ROLE MUST BE DEFINED PREVIOUSLY BY THE USER ***/CREATEORREPLACE MASKING POLICY"random_1_999"AS(val SMALLINT)RETURNSSMALLINT->CASEWHEN current_role() IN ('YOUR_DEFINED_ROLE_HERE')THEN valELSE UNIFORM(1, 999, RANDOM()) :: SMALLINTEND;ALTERTABLEIFEXISTS PUBLIC.table_name MODIFY COLUMN column_name/*** MSC-INFORMATION - MSCINF0033 - A MASKING POLICY WAS CREATED AS SUBSTITUTE FOR MASKED WITH ***/
SET MASKING POLICY"random_1_999";
DEFAULT
This pattern showcases some of the basic translation scenarios for DEFAULT property.
ALTERTABLE PUBLIC.table_nameADD intcol INTEGERDEFAULT0;ALTERTABLE PUBLIC.table_nameADD varcharcol VARCHAR(20) DEFAULT'';ALTERTABLE PUBLIC.table_nameADD datecol DATE-- ** MSC-ERROR - MSCEWI1088 - EXPRESSIONS LIKE FUNCTION CALLS, VARIABLES, OR NAMED CONSTANTS ARE NOT SUPPORTED ON DEFAULT OPTION IN SNOWFLAKE **
-- DEFAULT CURRENT_TIMESTAMP ;
ENCRYPTED WITH
This pattern showcases the translation for ENCRYPTED WITH property, which is commented out in the output code.
-- ** MSC-ERROR - MSCEWI4058 - ONE OR MORE OF THE TABLE ELEMENT PARTS ARE NOT SUPPORTED IN SNOWFLAKE: FILESTREAM CLAUSE **
--ALTER TABLE table2--ADD column1 varbinary(max)--FILESTREAM ;
SPARSE
In SQL Server, SPARSE is used to define columns that are optimized for NULL storage. However, when we're using Snowflake, we are not required to use this clause.
Snowflake performs optimizations over tables automatically, which mitigates the need for manual user-made optimizations.
SQL Server
-- ADD COLUMN DEFINITION formALTERTABLE table3ADD column1 intNULL SPARSE;----------------------------------------/* It also applies to the other forms */------------------------------------------ CREATE TABLE formCREATETABLEtable3( column1 INT SPARSE NULL);-- ALTER COLUMN formALTERTABLE table3ALTER COLUMN column1 INTNULL SPARSE;
Snowflake
-- ADD COLUMN DEFINITION formALTERTABLEIFEXISTS PUBLIC.table3ADD column1 INTNULL-- ** MSC-WARNING - MSCEWI1040 - THE STATEMENT IS NOT SUPPORTED IN SNOWFLAKE **-- SPARSE ;----------------------------------------/* It also applies to the other forms */------------------------------------------ CREATE TABLE formCREATE OR REPLACETABLEPUBLIC.table3 ( column1 INT-- ** MSC-WARNING - MSCEWI1040 - THE STATEMENT IS NOT SUPPORTED IN SNOWFLAKE **-- SPARSENULL);-- ** MSC-ERROR - MSCEWI4061 - ALTER COLUMN COMMENTED OUT BECAUSE SPARSE column IS NOT SUPPORTED IN SNOWFLAKE **--ALTER COLUMN form--ALTER TABLE table3--ALTER COLUMN column1 INT NULL SPARSE
ALTERTABLEIFEXISTS PUBLIC.table_nameADD column_name VARCHAR-- ** MSC-WARNING - MSCEWI1040 - THE STATEMENT IS NOT SUPPORTED IN SNOWFLAKE **--ROWGUIDCOL ;
Known Issues
1. Roles and users have to be previously set up for masking policies
Snowflake's Masking Policies can be applied to columns only after the policies were created. This requires the user to create the policies and assign them to roles, and these roles to users, in order to work properly. Masking Policies can behave differently depending on which user is querying.
SnowConvert does not perform this setup automatically.
2. Masking policies require a Snowflake Enterprise account or higher.
The Snowflake documentation states that masking policies are available on Entreprise or higher rank accounts.
SQL Server's DEFAULT property is partially supported by Snowflake, as long as its associated value is a constant.
4. FILESTREAM clause is not supported in Snowflake.
The entire FILESTSTREAM clause is commented out, since it is not supported in Snowflake.
5. SPARSE clause is not supported in Snowflake.
The entire SPARSE clause is commented out, since it is not supported in Snowflake. When it is added within an ALTER COLUMN statement, and it's the only modification being made to the column, the entire statement is removed since it's no longer adding anything.