Execute SQL script
Description
The Execute SQL Script transform runs a SQL script either once, during the initialization phase of the pipeline, or once for every input-row that the transform receives.
|
Pipeline source when Execute for each row is off (the default). Enable that option to run the script once per incoming row; hops are then required, and hops into one-shot mode are refused. |
When used for every input row, parameters can be passed to the SQL scripts specified in the transform. Only in this mode, input fields are passed on to the next hop.
The dialog is split into General, SQL, and Parameters tabs.
General
The General tab holds the database connection, the commit size, and optional statistics output fields.

| Option | Description |
|---|---|
Transform name |
Name of the transform; This name has to be unique in a single pipeline |
Connection |
Select a database connection to use |
Commit size |
Only used with Execute for each row.
Leave empty or set to |
Field to contain insert stats |
Optional: If you want to get an additional field in our stream with the number or records that where inserted, please define the field name here. |
Field to contain update stats |
Same as insert stats, but for updated rows. |
Field to contain delete stats |
Same as insert stats, but for deleted rows. |
Field to contain read stats |
Same as insert stats, but for read rows. |
The counts come from the number of affected rows the JDBC driver reports for each statement, attributed by the statement’s verb (also behind a WITH clause). MERGE, UPSERT and REPLACE statements report a single count for the rows they inserted, updated and deleted together; that count is reported as updated rows. Rows returned by SELECT statements count as read rows, except when the SQL is sent as a single statement.
The same counts show up in the transform’s own metrics: read rows as input (I), inserted rows as output (O), updated and deleted rows as updated (U).
An error hop on PostgreSQL and look-alikes
With a commit size and an error hop, on a database where a failed statement aborts the whole transaction, such as PostgreSQL:
-
a single INSERT, UPDATE, DELETE or MERGE whose text is the same for every row (bind parameters, or no
?at all) runs in a row window, on a database whose driver’s behaviour with a failed batch has been measured (PostgreSQL is one; see Table Output). Every row runs right away, without a savepoint. When a row fails, the rows before it in the same transaction are rolled back, sent again as one batch and committed, and only the failing row goes to the error hop. A clean row costs nothing extra. The counts of a row sent again are those of the batch; a driver that reports no count for a batched row (PostgreSQL withreWriteBatchedInserts, for one) counts it as one row. A row that is sent again can use up an extra sequence value and fire a non-transactional trigger again; -
other SQL (a script of several statements, text in which
?is replaced by field values, a query, DDL, or a statement with a RETURNING or OUTPUT clause) runs each row behind a savepoint, so only the failing row is undone. That costs a round trip more for every row.
Either way a row and its counts are passed on only once its transaction is committed, and when the transform fails or is stopped the open transaction is rolled back and its rows are not passed on.
A savepoint per row is still used on a connection shared by a transactional pipeline, and on every database whose driver’s behaviour with a failed batch has not been measured. To go back to a savepoint per row on a measured database:
-
set When a batch fails, the driver on the Advanced tab of the connection to As before, or
-
set the variable
HOP_DATABASE_BATCH_RECOVERYtoLEGACY, for every connection.
SQL
The SQL tab is where you specify the script to run, either inline or from a file.

You can keep the script in the SQL editor, or load it from an external .sql file with Load SQL from file.
Use a VFS path; variables in the path (for example ${PROJECT_HOME}/sql/script.sql) are resolved.
The file is read once when the transform initializes, not once per incoming row.
When a path is set, the SQL editor shows a read-only preview of the file contents.
Question marks (?) in the file still bind to the Parameters table in the same order as for inline SQL.
Leave the path empty to edit the script in the dialog (the previous default).
Enable Variable substitution to substitute Hop variables in the SQL (inline or loaded from the file) before the statement is executed.
| Option | Description |
|---|---|
Load SQL from file |
Optional VFS path to a |
SQL script to execute |
Specify the SQL to execute. Separate statements by ; and use question marks as place holders for parameter. When Load SQL from file is set, this editor is a read-only preview of the file. |
Execute for each row? |
Select this option to execute the SQL for each incoming row. In this case input fields can be used as parameters and are passed on to the output. When this option is unchecked, the SQL statement is executed at the transform initialization phase and inputs fields are not processed. |
Execute as a single statement |
This option does not split the statements by ; and will send the whole SQL to the database. |
Variable substitution |
In case you want to use variables in the SQL, e.g. ${table_name}, this option needs to be checked. If you are using Parameter fields, they are only used in conjunction with "question marks" in the SQL (see below). |
Quote Strings? |
This option adds quotes around the string according to the database dialect and also escapes special characters like CR, LF and the quote character itself. |
Parameters
The Parameters tab lists the input fields that replace question marks in the SQL, in order. Bind parameters and the parameters table are enabled when Execute for each row is selected on the SQL tab. Use Get Fields to fill the table from the previous transform.

| Option | Description |
|---|---|
Bind parameters? |
Check this option to bind parameters using prepared statements, otherwise this transform will perform a literal string replacement of the parameters. |
Parameters |
The list of parameters that will replace the question marks in the query in the given order. So the first question mark will be replaced by the first parameter, the second question mark by the second parameter etc. |
Samples
The samples project has transforms/execute-sql-script.hpl, which runs a CREATE TABLE IF NOT EXISTS employees statement once through the hop-samples connection.