- 3 Minutes to read
- Print
- DarkLight
- PDF
SQL Logic Step
- 3 Minutes to read
- Print
- DarkLight
- PDF
Overview
The Logic Step of 'SQL / Script' enables for in-database transformations to be performed using a query or a script (the SQL syntax to be used is that of your cloud data warehouse).
A SQL query is created to execute select statements, resulting in data as the outcome. In contrast, a SQL script serves the purpose of executing commands, such as Data Manipulation Language (DML) operations.
SQL Query:
To define the structure of the table that will be managed and created in the Target, a SQL SELECT clause is required at the transformation level. This specific SQL statement will determine the layout of the table. As Rivery handles table management, there's no need for a CREATE/ALTER TABLE clause.
SQL Script:
With the SQL Script option, you have the flexibility to execute free text operations and SQL Scripts on your instance. This allows you to execute various SQL clauses such as UPDATE, CREATE/ALTER TABLE, DROP TABLE, INSERT INTO, COPY, and even multi-command clauses in a single step.
- The SQL script is not encrypted in any way. Please avoid using credentials in the script.
- The SQL script runs according to user configurations. Users are responsible for any changes to the table, schema, or data that occur due to the script.
- Ensure the validity of your SQL clause using the Worksheet provided by your warehouse before pasting it into Rivery.**
- Here’s an example demonstrating the use of the SQL Script option with Snowflake Stored Procedures in a Rivery Logic River.
- Rivery's look has been updated, but it still serves the same functionality.
How it Works
- To begin, select SQL / Script as the Logic Step type and the cloud database to which you want to connect.
- In the Source section:
a. Select the Connection Name.
b. Enter your SQL script/query into the SQL field.
- If you're using colons, make sure they're preceded by double backslashes, or else the River will fail.
- A limitation of SQL querying in Snowflake is that it does not support the "WITH" clause.
- In Snowflake's SQL querying, refrain from using '--' for remarks, as this could result in failure of your Logic River.
- In Snowflake, the connection form includes a "Default Database/Schema" section. This allows you to specify the database and schema you want to work with, and the connection will automatically remember and use these as the default.
This simplifies the setup process for the target, saving time and effort.
Working With Variables
In SQL Logic step, users can leverage dynamic variables to establish connections between Rivers, automate tasks, and exchange data.
How To Use Logic River Variables
Select the 'Variables' tab in the upper right corner.
Add a Variable ('temp' is an example).
Please Note:
- To create an array, tick the 'Contains Multiple Values' box.
- If the item 'Clear Value On Start' is checked, the value of the variable will always be updated to the original value when a new River is formed, regardless of what happens to it during a River.
- Multiple variables can be defined.
- Variable Encryption is currently only availalbe in Python steps.
- Click Apply Changes.
- To use the variable(s), run this:
SELECT *
FROM {temp}
Please Note:
Make sure to run this code whenever you refer to a String:
SELECT *
WHERE my_string_field = '{Var_Name}'
Expand & Preview Results
To Expand & Preview Results click the diagonal arrows in the SQL field:
Results Tab
The Result tab displays the output of your SQL script/query.
Click Run to view the output:
When the output reaches the maximum of 500 rows, a notification appears.
Compiled SQL Tab
A compilation is the process of optimizing the query execution plan.
When variables are used in the query, the real value will be displayed in the compiled SQL tab.
'Compiled SQL' can only be used for SQL queries, not SQL scripts.
Here's an example:
Move & Scroll
To make things easier, the preview window may be moved and scrolled:
Download SQL
The SQL query can be downloaded to your local computer.
Click on the arrow pointing down in the upper right corner: