Redshift - Execute
In this article
Overview
You can use the Redshift Execute Snap to execute arbitrary SQL queries. It executes DML (SELECT, INSERT, UPDATE, DELETE) type statements. This Snap works best with single queries.
Snap type
The Redshift Execute Snap is a Write-type Snap that writes the results of the executed SQL queries.
Prerequisites
Supported Redshift database environment and Redshift database account with valid access control.
Support for Ultra Pipelines
Works in Ultra Pipelines.
Limitations
If you use the PostgreSQL driver (org.postgresql.Driver
) with the Redshift Snap Pack, it could result in errors if the data type provided to the Snap does not match the data type in the Redshift table schema. Either use the Redshift driver (com.amazon.redshift.jdbc42.Driver
) or use the correct data type in the input document to resolve these errors.
When the SQL statement property is an expression, the pipeline parameters are shown in the suggest, but not the input schema.
Multiple queries might not work, because the underlying JDBC driver does not support multiple queries. We recommend you to use the Redshift - Multi Execute Snap for running multiple queries.
Behavior Change
In 4.26, when the stored procedures were called using the Database Execute Snaps, the queries were treated as write queries instead of read queries. So the output displayed message and status keys after executing the stored procedure. If the stored procedure has no OUT parameters then only the message key is displayed with value success. If you have any existing Pipelines that are mapped with status key or previous description then those Pipelines will fail. So, you might need to revisit your Pipeline design.
In 4.27, all the Database Execute Snaps run stored procedures correctly, that is, the queries are treated as read queries. The output now displays message key, and OUT params of the procedure (if any). The status key is not displayed.
Snap Views
Type | Format | Number of Views | Examples of Upstream and Downstream Snaps | Description |
---|---|---|---|---|
Input | Document |
|
| A Snap that can contain data that is to be used with the JSON paths defined in the SQL, if any, or to be passed through. If the input view is defined, then the where clause substitutes incoming values for a specific query. |
Output | Document
|
|
| A document with the result set output, if any, and update count as return status from the Redshift SQL. The Snap output all records of a batch (as configured in your account settings) to the error view if the write fails during batch processing. If an output view is available and an update/insert/merge/delete statement was executed, then the original document that was used to create the statement will be output with the status of the executed statement. |
Error | Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the Pipeline by choosing one of the following options from the When errors occur list under the Views tab:
Learn more about Error handling in Pipelines. |
Snap Settings
Asterisk ( * ): Indicates a mandatory field.
Suggestion icon (): Indicates a list that is dynamically populated based on the configuration.
Expression icon ( ): Indicates the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.
Add icon ( ): Indicates that you can add fields in the field set.
Remove icon ( ): Indicates that you can remove fields from the field set.
Field Name | Field Type | Description |
---|---|---|
Label*
| String | Specify the name for the Snap. |
SQL statement*
| String/Expression | Specify the SQL statement to execute on the server.
Valid JSON paths that are defined in the WHERE clause for queries/statements are substituted with values from an incoming document. If the document is missing a value to be substituted into the query/statement, it will be written to the error view. If ‘$' is not part of the JSON path, it can be escaped by writing it as Following is an example of the procedure:
|
Query type
Default Value: Auto | Dropdown list/Expression | Select the type of query for your SQL statement (Read or Write). When Auto is selected, the Snap tries to determine the query type automatically. |
Pass through
| Checkbox | Select this checkbox to pass the input document through to the output view under the key 'original'. This property applies only to the Execute Snaps with SELECT statement.
|
Ignore empty result
| Checkbox | Select this checkbox to ignore empty result; no document will be written to the output view when a SELECT operation does not produce any result. |
Number of retries
Default Value: 0 | Integer/Expression | Specify the maximum number of retry attempts the Snap must make in case there is a network failure and is unable to read the target file. The request is terminated if the attempts do not result in a response.
|
Retry interval (seconds)
Default Value: 1 |
| Specify the time interval between two successive retry requests. A retry happens only when the previous attempt resulted in an exception.
|
Auto commit
| Dropdown list | Select one of the following options:
|
Snap Execution
| Dropdown list | Select one of the three modes in which the Snap executes. Available options are:
|
Troubleshooting
Error | Reason | Resolution |
---|---|---|
| This issue occurs due to incompatibilities with the recent upgrade in the Postgres JDBC drivers. | Download the latest 4.1 Amazon Redshift driver here and use this driver in your Redshift Account configuration and retry running the Pipeline. |
Additional Information
Scenarios to successfully execute your SQL statements
The non-expression form uses bind parameters, so it is much faster than executing N arbitrary SQL expressions.
Using expressions that join strings together to create SQL queries or conditions has a potential SQL injection risk and hence unsafe. Ensure that you understand all implications and risks involved before using concatenation of strings with '=' Expression enabled.
The '$' sign and identifier characters, such as double quotes (“), single quotes ('), or back quotes (`), are reserved characters and should not be used in comments or for purposes other than their originally intended purpose.
Single quotes in values must be escaped
Any relational database (RDBMS) treats single quotes ('
) as special symbols. So, single quotes in the data or values passed through a DML query may cause the Snap to fail when the query is executed. Ensure that you pass two consecutive single quotes in place of one within these values to escape the single quote through these queries. For example:
If String | To pass this value | Use |
Has no single quotes | Schaum Series | 'Schaum Series' |
Contains single quotes | O'Reilly's Publication | ' |
Recommendations
Be cautious when running your queries, because you can drop your database and lock tables while executing SQL statements.
Running multiple queries might not work with the Redshift - Execute Snap. If you need to run multiple queries, we recommend you to use the Redshift -Multi Execute Snap.
ETL Transformations and Data Flow
This Snap enables the following ETL operations/flows:
Extract data from an existing Redshift Table.
Transform any input document SnapLogic types to Redshift JDBC types for any input and transform any output document Redshift JDBC types to SnapLogic types for output.
Load data in the Redshift table.
The SQL (to be executed) is passed to Redshift. Here’s the detailed data flow:
The Snaps collects the user account information, and the SQL statement (after any expression evaluation), and any JDBC jars defined in the Redshift database account. JDBC jars defined in the Redshift database account are at customer discretion and should be Redshift approved/supported.
Valid JSON paths that are defined in the WHERE clause for queries/statements will be substituted with values from an incoming document as a prepared statement. The substituted values will be transformed from the SnapLogic type value to the appropriated JDBC type values based on the database's column type. If there are no JSON paths then a JDBC query will be utilized instead of a prepared statement.
Successful execution may create a result set. The result set columns will be transformed from the JDBC type value to the SnapLogic type value.
Data errors may occur, therefore an error view should be created to handle these conditions. If the batch has a data error the error data will be written to the error view and the rest of the batch will not be processed. However, a batch data error will not stop subsequent batches from executing.
Select SQLs will not use auto-commit. For non-select SQL, commit happens at successful batch completion when the database account has Auto commit enabled. If the database account does not have Auto commit enabled, commit happens at end of the successful Snap run. Therefore the Auto commit the setting must be configured to be pr