Database¶
SQL¶
Runs SQL against SQL Server, PostgreSQL or SQLite, once per input item. Query returns the rows as items, Execute the number of affected rows.
Inputs: main · Outputs: main
| Parameter | Type | Description |
|---|---|---|
Connection (required)credentialId |
credential (Connection String) | Connection String credential: which database (sqlserver, postgres or sqlite) and how to reach it. |
Databaseprovider |
one of: fromCredential, sqlServer, postgreSql, sqlite |
Kind of database; usually it comes from the credential. fromCredential: The database named in the credential (sqlserver, postgres or sqlite).sqlServer: Microsoft SQL Server or Azure SQL.postgreSql: PostgreSQL.sqlite: A SQLite file.In Advanced. Default: fromCredential. |
Operationoperation |
one of: query, execute |
Read rows, or change data. query: SELECT: every result row becomes an item.execute: INSERT, UPDATE, DELETE, …: one item with the number of affected rows.Default: query. |
SQL (required)sql |
code | The statement; use @name for values, e.g. WHERE id = @id. They are passed as parameters, never inserted into the SQL text. Source code; {{ }} is not evaluated. |
Parametersparameters |
key/value pairs | @name → value, e.g. id → {{ $json.id }}; evaluated per item. |
Timeout (seconds)commandTimeout |
integer | Longest wait for a statement; 0 waits without limit. In Advanced. Default: 30. |
Example: Read the open orders of a customer
Runs once per input item; every row becomes an item. The value comes in as the parameter @customer, never as SQL text.
Parameters:
{
"operation": "query",
"sql": "SELECT id, amount FROM orders WHERE customer = @customer AND status = 'open'",
"parameters": {
"customer": "{{ $json.customer }}"
}
}
Input:
[
{
"customer": "Anna"
}
]
Output:
[
{
"id": 17,
"amount": 120.5
},
{
"id": 21,
"amount": 80
}
]
Example: Mark orders as shipped
Parameters:
{
"operation": "execute",
"sql": "UPDATE orders SET status = 'shipped' WHERE id = @id",
"parameters": {
"id": "{{ $json.id }}"
}
}
Input:
[
{
"id": 17
}
]
Output:
[
{
"affectedRows": 1
}
]