CREATE MACRO

Translation reference to convert Teradata CREATE MACRO to Snowflake Scripting

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Description

The Teradata CREATE MACRO defines one or more statements that are commonly used or that perform a complex operation, thus avoiding writing the same sequence of statements multiple times. The macro is executed when it is called by the EXECUTE statement.

For more information about CREATE MACRO click here.

CREATE MACRO <macroname> [(parameter1, parameter2,...)] ( 
   <sql_statements> 
);

[ EXECUTE | EXEC ] <macroname>;

Sample Source Patterns

Setup data

The following code is necessary to execute the sample patterns present in this section.

Basic Macro

Since there is no macro object in Snowflake, the conversion tool transforms Teradata macros into Snowflake Scripting stored procedures. Besides, to replicate the functionality of the returned result set, in Snowflake Scripting, the query that is supposed to return a data set from a macro is assigned to a RESULTSET variable which will then be returned.

Teradata

Snowflake Scripting

Macro Calls Another Macro

SnowConvert supports the scenario where a macro calls another macro and, by transitivity, a result set is returned by getting the results from Snowflake's RESULT_SCAN(LAST_QUERY_ID()).

Teradata

Snowflake Scripting

Macro with no result set

Not all macros are intended to return a result set. The mentioned scenario is also supported.

Teradata

Snowflake Scripting

Macro returns multiple result sets

In Teradata, macros can return more than one result set from a single macro.

Snowflake Scripting procedures only allow one result set to be returned per procedure. To replicate Teradata behavior, when there are two or more result sets to return, they are stored in temporary tables. The Snowflake Scripting procedure will return an array containing the name of the temporary tables.

Teradata

Snowflake Scripting

Visualize Result Rets

Executing the above procedure on Snowflake, an array with temporary table names in it will be returned:

[ "RESULTSET_93D50CBB_F22C_418A_A88C_4E1DE101B500", "RESULTSET_6BDE39D7_0554_406E_B52F_D9E863A3F15C"]

It is necessary to execute the following queries to display the result sets just like in Teradata.

Known Issues

No issues were found.

  1. SSC-FDM-0020: Multiple result sets are returned in temporary tables.

Last updated