Azure Synapse SQL Execute

Overview

You can use this Snap to execute Transact-SQL queries.

Note: This Snap works only with single queries.

Azure Synapse SQL Execute Snap Overview

Prerequisites

Limitations

When the table name contains single quote characters, the No table found error is displayed. This is because of the JDBC driver limitation.

Known issues

None.

Snap views

Type Description Examples of upstream and downstream Snaps
Input

Optional.A document that provides values for SQL statement parameters.

Output

Document containing the execution status and results.

Learn more about Error handling.

Snap settings

Legend:
  • Expression icon (): Allows using pipeline parameters to set field values dynamically (if enabled). SnapLogic Expressions are not supported. If disabled, you can provide a static value.
  • SnapGPT (): Generates SnapLogic Expressions based on natural language using SnapGPT. Learn more.
  • Suggestion icon (): Populates a list of values dynamically based on your Snap configuration. You can select only one attribute at a time using the icon. Type into the field if it supports a comma-separated list of values.
  • Upload : Uploads files. Learn more.
Learn more about the icons in the Snap settings dialog.
Field/Field set Description
Label

String

Required.Specify a unique name for the Snap.

Default value: Azure Synapse SQL - Execute

Example: Execute EmployRecords

SQL Statement

String/Expression

Required.Specify the SQL statement to execute on the server. We recommend you to add a single query in the SQL Statement field. There are two possible scenarios that you encounter when working with SQL statements in SnapLogic.

Scenarios to successfully execute your SQL statements

Scenario 1: Executing SQL statements without expressions.

If the expression toggle of the SQL statement field is not selected:

  • The SQL statement must not be within quotes.
  • The $<variable_name> parts of the SQL statement are expressions. In the below example, $id and $book.
  • email = '[email protected]' or email = $email
  • emp=$emp
  • Additionally, the JSON path is allowed only in the WHERE clause. If the SQL statement starts with SELECT (case-insensitive), the Snap regards it as a select-type query and executes once per input document. Else, it regards it as write-type query and executes in batch mode.

Scenario 2: Executing SQL queries using expressions.

If the expression toggle of the SQL statement field is selected:

  • The SQL statement must be within quotes.
  • The + $<variable_name> + parts of the SQL statement are expressions, and must not be within quotes. In the below example, $tablename.
  • The $<variable_name> parts of the SQL statement are bind parameter, and must be within quotes. In the below example, $id and $book.
  • "EMPNO=$EMPNO and ENAME=$EMPNAME"
  • "emp='" + $emp + "'"
  • "EMPNO=" + $EMPNO + " and ENAME='" + $EMPNAME+ "'"
  • Do not specify Table name and column names as bind parameters. You can only provide values as bind parameters.

The non-expression form uses bind parameters, so it is faster than executing N arbitrary SQL expressions.

Warning: 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.
Note: 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.

Default value: None

Example: INSERT into SnapLogic.book (id, book) VALUES ($id,$book)

Query type

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.
  • If the execution result of the query is not as expected, you can change the query type to Read or Write.

Default value: Auto

Example: Read

Ignore empty result

Checkbox

Select this checkbox to enable the Snap to ignore empty result and not write a document to the output view when a SELECT operation does not produce any result. If you deselect this checkbox and with the default Pass through option, the input document is passed through to the output view.

Default value: Deselected

Number of Retries

Integer/Expression

Specify the maximum number of retry attempts the Snap must make in case of network failure.

Note:

When you set the Number of retries to more than 0, the Snap generates duplicate records when the connection is not established. To prevent duplicate records, we recommend that you follow one of the following:

  • Set the Number of retries to 0 (default value) to prevent duplicate records from being passed downstream while executing a pipeline.
  • Use a Primary key to prevent records from being inserted into the database.
  • Use an Upsert instead of an Insert statement.

Default value: 0

Example: 3

Retry Interval (seconds)

Integer/Expression

Specify the time interval between two successive retry requests. A retry happens only when the previous attempt resulted in an exception.

Default value: 1

Example: 10

Auto Commit

Dropdown list

Select one of the following options to override the state of Auto commit on the account:

  • True - Executes with auto-commit enabled regardless of the value set for Auto commit in the Account used by the Snap.
  • False - Executes with auto-commit disabled regardless of the value set for Auto commit in the Account used by the Snap.
  • Use account setting - Executes with Auto commit property value inherited by the Account used by the Snap.
Note: Auto Commit may be enabled for certain use cases if PostgreSQL JDBC driver is used in either Redshift, PostgreSQL or Generic JDBC Snap. But the JDBC driver may cause out of memory issues when Select statements are executed. In such cases, Auto commit in Snap should be set to False and the Fetch size in the Account settings can be increased for optimal performance.

Behavior of DML Queries in Database Execute Snap with respect to Auto Commit setting:

  • DDL queries used in the Database Execute Snap will be committed by the Database itself, regardless of the Auto-commit setting.
  • When Auto commit is set to false for the DML queries, the commit is called at the end of the Snap's execution.
  • The Auto commit needs to be true in a scenario where the downstream Snap does depend on the data processed on an Upstream Database Execute Snap containing a DML query.
  • When the Auto commit is set to the Use account setting on the Snap, the account level commit needs to be enabled.

Default value: Use account setting

Example: True

Snap execution

Dropdown list
Choose one of the three modes in which the Snap executes. Available options are:
  • Validate & Execute: Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only: Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Default value: Execute only

Example: Validate & execute

Troubleshooting

Table 1. Error Messages and Resolutions
Error Reason Resolution
Implicit conversion from data type varbinary to date is not allowed. This error is because of an issue with the jOOQ auto cast() expression in the transformed query. Use the CONCAT reference for each value to run the query.