Skip to end of banner
Go to start of banner

PostgreSQL - Execute

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 40 Next »

On this Page

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.
 

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

[None]


Support and limitations:
  • Works in Ultra Task Pipelines.
  • Does not support $$ as an escape character for enclosing string input, as $ is a reserved character for variable substitution in SnapLogic.
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.
    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.

  • 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.

Account: 

This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See Configuring PostgreSQL Accounts 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.

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*


Specify 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*


Specify the SQL statement to execute on the server. 

Scenarios to successfully execute your SQL statements

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.

Examples:

  • email = 'you@example.com' or email = $email 

  • emp=$emp

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.
Table name and column names must not be provided as bind parameters. Only values can be provided as bind parameters.

Examples:


  • "EMPNO=$EMPNO and ENAME=$EMPNAME"

  • "emp='" + $emp + "'"

  • "EMPNO=" + $EMPNO + " and ENAME='" + $EMPNAME+ "'"


 

Known Issues

  • When the SQL statement property is an expression, the Pipeline parameters are shown in the suggest, but not the input schema.

     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 SQL statement will return a PGObject when returning non-standard types.


  • 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.
  • 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 valueUse
Has no single quotes
Schaum Series
'Schaum Series'
Contains single quotes
O'Reilly's Publication
'O''Reilly''s Publication'

Default Value: [None]

Query type

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

Pass through


Select this checkbox to pass the input document 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


Number of retries

Specify the maximum number of attempts to be made to receive a response. The request is terminated if the attempts do not result in a response.

Default Value: 0
Example: 3

  • If the value is larger than 0, the Snap first downloads the target file into a temporary local file. If any error occurs during the download, the Snap waits for the time specified in the Retry interval and attempts to download the file again from the beginning. When the download is successful, the Snap streams the data from the temporary file to the downstream Pipeline. All temporary local files are deleted when they are no longer needed.
  • Ensure that the local drive has sufficient free disk space to store the temporary local file.

Retry interval (seconds)

Specifies 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

Select one of the options for this property to override the state of the Auto commit property on the account. The Auto commit at the Snap-level has three values: TrueFalse, and Use account setting. The expected functionality for these modes are:

  •  True - The Snap will execute with auto-commit enabled regardless of the value set for Auto commit in the Account used by the Snap.
  •  False - The Snap will execute with auto-commit disabled regardless of the value set for Auto commit in the Account used by the Snap.
  • Use account setting - The Snap will execute with Auto commit property value inherited by the Account used by the Snap.

Default Value: Use account setting

'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 those cases, “Auto commit" in Snap property should be set to ‘False’ and the Fetch size in the “Account setting" can be increased for optimal performance.

Behavior of DML Queries in Database Execute Snap when auto-commit is false

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.

Snap execution

Select 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.

Troubleshooting

ErrorReasonResolution

Pipeline is no longer running.

When you use numerous self-joins in SQL SELECT statements with bind values, the Snap is likely to fail after the 11th statement.

Use either of the following workaround solutions to avoid Pipeline failure:

  • Edit your query to submit upstream values using expression language, instead of using placeholders.

  • Split your complex query into multiple simple queries, run them, and join the data using other SnapLogic Snaps in the Transform Snap Pack.

Examples

Inserting a record in a table using stored procedure in PostgreSQL-Execute Snap

Stored procedure:

A stored procedure is a named set of pre-written instructions or commands that are saved in a database. Instead of giving instructions whenever you want to perform an operation like inserting, updating, fetching, or deleting records, you write them down in a procedure. Then, whenever you need to do that specific task again, you call the stored procedure.

This example pipeline demonstrates how to create a stored procedure and call the stored procedure to insert a record in an existing table.

Download this pipeline.

Step 1: Configure the PostgreSQL-Execute Snap with Create Procedure statement to create a stored procedure, genre_insert_data, to insert GenreId and Name in the Genre table.

a. CREATE OR REPLACE PROCEDURE public.genre_insert_data("GenreId" integer, "Name" character varying ) statement creates a stored procedure that has INPUT parameters GenreId and Name values.

b. INSERT INTO "public"."Genre" VALUES ("GenreId", "Name"); this statement inserts the values in the Genre table.

Step 2: Configure the PostgreSQL-Execute Snap with a call statement to trigger the stored procedure by passing values for GenreId and Name.

Step 3: Configure the Table Name and GenreId in the PostgreSQL-Select Snap as follows to fetch the inserted record to verify if the record has been inserted.

Step 4: On validation, the PostgreSQL-Select Snap fetches the previously inserted record.

The following single-Snap Pipeline runs an SQL query containing a JOIN command to collate data between two PostgreSQL tables.

Download this Pipeline

Let us consider the following tables in a PostgreSQL DB. Notice that the column employee_id is common between these tables.

Table 1: AVemployeesTable 2: AVempsalary

The Snap accesses the PostgreSQL tables using a valid account and runs an SQL query that contains a JOIN command based on the following settings:

The output preview after executing this Pipeline displays the result for the SQL query.

Upon joining the two tables as defined in the SQL query, we can see the employee_id column in the second table is prefixed with its table name AVempsalary to differentiate it from the column with the same name in the AVemployees table. This is how the PostgreSQL - Execute Snap handles column with conflicting names in tables when the SQL statement contains a JOIN command.

Downloads

Important steps to successfully reuse Pipelines

  1. Download and import the pipeline into the SnapLogic application.
  2. Configure Snap accounts as applicable.
  3. Provide pipeline parameters as applicable.

  File Modified
No files shared here yet.

Snap Pack History

 Click to view/expand
Release Snap Pack VersionDateType  Updates
November 2024main29029 StableUpdated and certified against the current SnapLogic Platform release.

August 2024

main27765

 

Stable

Updated and certified against the current Snaplogic Platform release.

May 2024437patches27531 Latest
May 2024437patches27416 Latest
  • Fixed an issue with the PostgreSQL—Insert Snap that exposed sensitive information in the error message when the batch operation was not successful.
  • Fixed an issue with the PostgreSQL—Bulk Load Snap that caused incorrect or invalid binary data to be inserted when the column was of Binary type.

May 2024437patches27172 Latest
  • Added the PostgreSQL - Vector Search Snap to enable advanced vector-based queries using the SELECT statement.
  • Added vector data type support for PostgreSQL - Insert and PostgreSQL - Update Snaps.

  • Upgraded the PostgreSQL JDBC driver from v9.4.1207 to v42.7.2 (Java 8). This upgrade will be part of the GA release on August 14, 2024 (Stable release). As part of this upgrade, the 42.7.2 JDBC driver is bundled with the PostgreSQL Snap Pack as the default JDBC driver. Your existing PostgreSQL pipelines that use the default driver (bundled with the PostgreSQL Snap Pack) might break.

    Behavior change:

    This driver upgrade has resulted in specific behavior changes in errors, status codes, and success and failure messages. Learn more.

May 2024437patches26634 LatestFixed an issue with PostgreSQL - Execute Snap that produced logs causing node crashes.
May 20244postgresupgrade26570 -

Upgraded the PostgreSQL JDBC driver from v9.4.1207 to v42.7.2 (Java 8). This upgrade will be part of the latest release on July 10,2024 and Stable release (GA) on August 14, 2024. As part of this upgrade, the 42.7.2 JDBC driver is bundled with the PostgreSQL Snap Pack as the default JDBC driver. Your existing PostgreSQL pipelines that use the default driver (bundled with the PostgreSQL Snap Pack) might break.

Behavior change:

This JDBC driver upgrade has resulted in specific behavior changes in errors, status codes, and success and failure messages. Learn more

May 2024main26341 StableUpdated the Delete Condition (Truncates a Table if empty) field in the PostgreSQL - Delete Snap to Delete condition (deletes all records from a table if left blank) to indicate that all entries will be deleted from the table when this field is blank, but no truncate operation is performed.
February 2024main25112 StableUpdated and certified against the current SnapLogic Platform release.
November 2023435patches23831 Latest

Fixed an issue with the PostgreSQL-Execute and PostgreSQL-Select Snaps that added escape characters ('\\') in the output for JSONB datatype.

November 2023main23721

 

StableUpdated and certified against the current SnapLogic Platform release.

August 2023

main22460

 


Stable

The PostgreSQL - Execute Snap now includes a new Query type field. When Auto is selected, the Snap tries to determine the query type automatically.

May 2023433patches21298 Latest

Fixed an issue with the PostgreSQL Insert Snap that inconsistently inserted some columns and missed the remaining columns(especially the Time fields), when the data was passed in the JSON format from an upstream Snap.

May 2023

main21015 

Stable

Upgraded with the latest SnapLogic Platform release.

February 2023 432patches20409 LatestThe PostgreSQL - Bulk Load and PostgreSQL - Insert Snaps no longer fail with the message ERROR: type modifier is not allowed for type 'bytea' when creating a new table if Create table if not present is selected and the target table does not exist. This issue occurred when metadata from the second input view document contained columns of the bytea data type.
February 2023 main19844 StableUpgraded with the latest SnapLogic Platform release.
November 2022

431patches19454

 Latest

The PostgreSQL Snap Pack supports geospatial data types.

November 2022main18944 Stable
  • The PostgreSQL - Bulk Load Snap can now process records with more than 16 KB in the document without encountering the BufferOverflowException because the default value of 16 KB for byte buffer size is now removed.
  • The PostgreSQL - Insert Snap now creates the target table only from the table metadata of the second input view when the following conditions are met:

    • The Create table if not present checkbox is selected.

    • The target table does not exist.

    • The table metadata is provided in the second input view.

September 2022430patches18149 Latest

The PostgreSQL Select and PostgresSQL Execute Snaps now read NaN values in Numeric columns when used with a PostgreSQL Account configured with the latest postgresql-42.5.0.jar driver.

September 2022430patches17894 Latest

The PostgreSQL Select Snap now works as expected when the table name is dependent on an upstream input.

August 2022430patches17700 LatestThe PostgreSQL - Bulk Load Snap can now process the records with more than 16KB in the document without encountering BufferOverflowException because the default value of 16KB for byte buffer size is now removed.
August 2022main17386 StableEnhanced the PostgreSQL Account and PostgreSQL Dynamic Account with SSH Tunneling configurations to encrypt the network connection between the client and the PostgreSQL Database server, thereby ensuring the secure network connection.
4.29 Patch429patches17036 Latest

Enhanced the PostgreSQL Account and PostgreSQL Dynamic Account with SSH Tunneling configurations to encrypt the network connection between the client and the PostgreSQL Database server, thereby ensuring a secure network connection.

4.29

main15993

 

Stable

Upgraded with the latest SnapLogic Platform release.

4.28main14627 StableUpdated the label for Delete Condition to Delete Condition (Truncates Table if empty) in the PostgreSQL Delete Snap.
4.27 Patch427patches13149 Latest

Fixed an issue with PostgreSQL - Execute Snap, where the Snap failed when using Delete query with the RETURNING function.

4.27main12833 Stable

Enhanced the PostgreSQL - Execute Snap to invoke stored procedures.

4.26main11181 StableUpgraded with the latest SnapLogic Platform release.
4.25 Patch425patches9879 Latest

Enhanced the performance of PostgreSQL - Bulk Load Snap significantly. SnapLogic anticipates that the Snap will execute up to 3 times faster than the previous version for enterprise workloads.

4.25main9554
 
StableUpgraded with the latest SnapLogic Platform release.
4.24main8556
Stable

Enhanced the PostgreSQL - Select Snap to return only the selected output fields or columns in the output schema (second output view) using the Fetch Output Fields In Schema check box. If the Output Fields field is empty all the columns are visible. 

4.23main7430
 
StableUpgraded with the latest SnapLogic Platform release.

4.22 Patch

422patches6879 Latest

Fixed the PostgreSQL - Bulk Load Snap by preventing it from adding extra double quotes when loading values from input documents.

4.22main6403
 
StableUpgraded with the latest SnapLogic Platform release.
4.21 Patch421patches6272 Latest

Fixed the issue where Snowflake SCD2 Snap generates two output documents despite no changes to Cause-historization fields with DATE, TIME and TIMESTAMP Snowflake data types, and with Ignore unchanged rows field selected.

4.21 Patch

421patches6144 Latest

Fixed the following issues with DB Snaps:

  • The connection thread waits indefinitely causing the subsequent connection requests to become unresponsive.
  • Connection leaks occur during Pipeline execution.

4.21 Patch

MULTIPLE8841 Latest

Fixed the connection issue in Database Snaps by detecting and closing open connections after the Snap execution ends. 

4.21snapsmrc542

 

StableUpgraded with the latest SnapLogic Platform release.
4.20snapsmrc535
 
StableUpgraded with the latest SnapLogic Platform release.
4.19 Patch db/postgres8409 Latest

Fixed an issue with the PostgreSQL - Update Snap wherein the Snap is unable to perform operations when:

  • An expression is used in the Update condition property.
  • Input data contain the character '?'.
4.19snaprsmrc528
 
Stable

Added new Snap PostgresSQL Bulk Load.

4.18 Patchpostgres8021 Latest

Fixed an issue with the PostgreSQL grammar to better handle the single quote characters.

4.18snapsmrc523
 
StableUpgraded with the latest SnapLogic Platform release.
4.17 Patch db/postgres7588 Latest

Fixed an issue with tables sharing an overlapping column name wherein Pipeline execution fails due to the table collision.

4.17ALL7402
 
Latest

Pushed automatic rebuild of the latest version of each Snap Pack to SnapLogic UAT and Elastic servers.

4.17snapsmrc515
 
Latest
  • Fixed an issue with the PostgreSQL Execute Snap wherein the Snap would send the input document to the output view even if the Pass through field is not selected in the Snap configuration. With this fix, the Snap sends the input document to the output view, under the key original, only if you select the Pass through field.
  • Added the Snap Execution field to all Standard-mode Snaps. In some Snaps, this field replaces the existing Execute during preview check box.
4.16 Patch db/postgres6822 Latest

Fixed an issue with the Lookup Snap passing data simultaneously to output and error views when some values contained spaces at the end.

4.16snapsmrc508
 
StableUpgraded with the latest SnapLogic Platform release.
4.15 Patch db/postgres6333 Latest

Replaced Max idle time and Idle connection test period properties with Max life time and Idle Timeout properties respectively, in the Account configuration. The new properties fix the connection release issues that were occurring due to default/restricted DB Account settings.

4.15snapsmrc500
 
StableUpgraded with the latest SnapLogic Platform release.
4.14snapsmrc490
 
Stable

Added support for Amazon Aurora and Azure SQL DB.

4.13

snapsmrc486

 
StableUpgraded with the latest SnapLogic Platform release.
4.12 PatchMULTIPLE4967 Latest

Provided an interim fix for an issue with the PostgreSQL 10 accounts by re-registering the driver for each account validation. The final fix is being shipped in a separate build.

4.12 Patch

postgres4832 Latest

Updated the driver from version 8.4.704 to version 9.4.1207 to support PostgreSQL v10 servers.

4.12

snapsmrc480

 
StableUpgraded with the latest SnapLogic Platform release.

4.11 Patch 

db/postgres4290 Latest

PostgreSQL Snap Pack - Fixed an issue when inserting a valid NaN value into a column.

4.11snapsmrc465
 
StableUpgraded with the latest SnapLogic Platform release.
4.10 Patchpostgres3773 Latest

Previously the Postgres PGObject datatype could not be serialized. It is now handled as a String.

4.10

snapsmrc414

 
Stable

Added Auto commit property to the Select and Execute Snaps at the Snap level to support overriding of the Auto commit property at the Account level.

4.9.0 Patchpostgres3134 Latest

PostgreSQL Execute: New Snap advanced property Auto commit has been implemented to fix the Select query error in PostgreSQL replica servers.

4.9 Patch

postgres3072 Latest

Fixed an issue regarding connection not closed after login failure; Expose autocommit for "Select into" statement in PostgreSQL Execute Snap and Redshift Execute Snap.

4.9snapsmrc405
 
StableUpgraded with the latest SnapLogic Platform release.
4.8.0 Patchpostgres2757 Latest

Potential fix for JDBC deadlock issue.

4.8.0 Patch

postgres2712 Latest

Fixed PostgreSQL Snap Pack rendering dates that are one hour off from the date returned by database query for non-UTC Snaplexes.

4.8.0 Patch

postgres2696

 


Latest

Addressed an issue where some changes made in the platform patch MRC294 to improve perfomance caused Snaps in the listed Snap Packs to fail.

4.8

snapsmrc398

 
Stable
  • Info tab added to accounts.
  • Database accounts now invalidate connection pools if account properties are modified and login attempts fail.
4.7.0 Patchpostgres2192 Latest

Fixed an issue for database Select Snaps regarding Limit rows not supporting an empty string from a pipeline parameter.

4.7.0 Patch

postgres2185 Latest

Resolved an issue with the PostgreSQL Execute Snap failing with a “java.util.regex.Pattern” error.

4.7

snapsmrc382

 
StableUpgraded with the latest SnapLogic Platform release.
4.6snapsmrc362
 
StableUpgraded with the latest SnapLogic Platform release.
4.5.1

postgres1584

 
Stable
  • Resolved an issue in the PostgreSQL - Execute Snap that resulted from restrictions on the 'with' operator in conjunction with an 'insert' statement.

  • Resolved an issue in the PostgreSQL Snaps that resulting from restrictions on the 'with' operator in conjunction with the RECURSIVE keyword.

4.4.1NA StableUpgraded with the latest SnapLogic Platform release.
4.4NA Stable
  • Resolved an issue with PostgreSQL Select Snap not parsing JSON data type correctly.
  • Note: The fix for this issue required updating libraries that impacted all database Snaps except those for MongoDB.
4.3.2NA Stable

This Snap Pack is now compatible with the PostgreSQL drivers available in 4.3 Patch mrc222.

NANA Stable
  • PostgreSQL Insert Snap: resolved an issue where it inserts a negative value when the input data was out of range.
  • PostgreSQL Snaps did not properly handle when a table name was created in mixed case.
  • JSON paths in WHERE clauses should be processed as bind values after the expression is evaluated.
NANA Stable
  • A - otd:6828 Postgres Snap shows wrong data type in preview for timestamp withtime zone data type
  • Dynamic DB queries now supported in the Execute Snap.
  • The SQL statement property now can be set as an expression property. When it is an expression, it will be evaluated with each input document and one SQL statement per each input document will be executed.
  • Known issue: When the SQL statement property is an expression, the pipeline parameters are shown in the suggest, but not the input schema.
  • With the SQL statement property set as an expression, the Snap can be exposed to SQL injection. Please use this feature with caution.
NANA Stable
  • PostgreSQL Insert: Enhanced data type support.
  • PostgreSQL Lookup: bug fixes on lookup failures; Pass-though on no lookup match property added to allow you to pass the input document through to the output view when there is no lookup matching.
    • PostgreSQL Select Snap: added support for handling array types.

  • No labels