Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added the Advanced Properties field


Snap type:

Write


Description:

This Snap allows you to execute arbitrary SQL.

Valid JSON paths that are defined in the where clause for queries/statements will be substituted with values from an incoming document. Documents will be written to the error view if the document is missing a value to be substituted into the query/statement.
 
If a select query is executed, the query's results are merged into the incoming document and any existing keys will have their values overwritten. On the other hand, the original document is written if there are no results from the query.
 

Note
You can drop your database with it, so be careful.


Prerequisites:

[None]


Support and limitations:


Account: 

This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See PostgreSQL Account for information on setting up this type of account.

Views:


InputThis Snap allows zero or one input views. If the input view is defined, then the where clause can substitute incoming values for a given expression.
OutputThis Snap allows zero or one output view and produces documents in the view.
Error

This Snap has at most one error view and produces zero or more documents in the view.

Note

Database Write Snaps output all records of a batch (as configured in your account settings) to the error view if the write fails during batch processing.



Settings

Label


Required.The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline.

SQL statement


Required.Specifies the SQL statement to execute on the server. 


There are two possible scenarios that you encounter when working with SQL statements in SnapLogic. You must understand the following 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.


For example:



Additionally, the JSON path (e.g. $myName) 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. If not, it regards it as write-type query and executes in batch mode.


Scenario 2: Executing SQL queries with 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 is bind parameter and must be within quotes. In the below example, $id and $book.

Note
Table name and column names must not be provided as bind parameters. Only values can be provided as bind parameters.

For example:



 
Known issue: When the SQL statement property is an expression, the pipeline parameters are shown in the suggest, but not the input schema.

Note

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


Warning

With the SQL statement property set as an expression, the Snap can be exposed to SQL injection. Please use this feature with caution.


Known issue: The SQL statement will return a PGObject when returning non-standard types.


Note

Non-standard types include standard PostgreSQL extensions such as JSON or XML, types defined in third party extensions such as PostGIS, or types defined via CREATE TYPE color AS ENUM (RED, GREEN, BLUE). They can be converted to strings using CAST(x AS TEXT) where 'x' is the name of the column.

Default value: [None]


Pass through


If selected, the input document will be passed through to the output view under the key 'original'. This property applies only to the Execute Snaps with SELECT statement.

Default value: Selected


Ignore empty result


If selected, no document will be written to the output view when a SELECT operation does not produce any result. If this property is not selected and the Pass through property is selected, the input document will be passed through to the output view.

Default value: Not selected


Advanced properties  

By default, the advanced properties are not required and is an empty table property. Press "+" button to add an advanced property if a value other than the default value should be set.

Place the mouse over the word "Values" to see default values for advanced properties.

Default value: [None]

Properties: Auto Commit

Enter true or false.

This advanced property applies only if the SQL statement property is a SELECT query. If the SQL statement property is of other types (e.g. INSERT, UPDATE, SELECT ... INTO, etc.), this property value is ignored.

If the Auto commit in the account is set to true, the PostgreSQL JDBC driver stores the entire result set of a SELECT query before it provides the result set to the Snap. If the result set is larger than the available system memory, it may cause an "Out of Memory" situation, rendering the Snaplex node inoperative. Therefore, the Snap automatically turns off the Auto commit during the SELECT operation so that the JDBC driver streams result sets from the server to the Snap (the number of rows in each fetch of results from the driver is as specified in the account's "Fetch size" property).

However, in some use cases (e.g. when using a PostgreSQL replica), the feature of automatic turning-off auto-commit may cause errors in the SELECT query if an UPDATE or INSERT query is being executed simultaneously in another Snap elsewhere in the same pipeline. In such cases, this advanced property can be used with 'Auto commit' = true to override the setting and prevent the error from being thrown. The "'Auto commit' = true" entry will force the Auto commit to "True" during the SELECT query execution. If the "'Auto commit' = true" entry causes out of memory because of the result set of SELECT query being larger than the available system memory, instead of using this advance property, the Fetch size property in the account can be used to prevent both out of memory and other errors. The value of Fetch size should be large enough to avoid the SELECT query error and small enough to prevent out of memory. Also, in such case, the larger the Fetch size is, the higher performance of the SELECT query operation.

Default value:  empty (null) If 'Auto commit' is not selected in the Advanced properties, the state of 'Auto commit' in the account will remain unchanged.

Execute during preview


Enables you to execute the Snap during the Save operation so that the output view can produce the preview data.

Default value:  Not selected


Insert excerpt
PostgreSQL Snap Pack
PostgreSQL Snap Pack
nopaneltrue