Skip to main content
Version: 5.2

db

Description

Executes a query to a database.

Syntax

db connection=<field> query=[<string> | <field>] [<timeout>]

Required Arguments

ParameterSyntaxDescription
connectionconnection=<field>Connection name.
queryquery=[<string> | <field>]SQL query.
info

If a data retrieval query is executed, the current data is replaced with new data. If a data processing query is executed, the resulting data contains the current data.

Time Stamps

A database query can include the {{_earliest}} or {{_latest}} placeholders, which will be replaced with the earliest or latest values from the source command.

Optional Arguments

ParameterSyntaxDefaultDescription
timeout<int>Taken from db_query or cluster setting "sme.sa.timeout.db".Query execution timeout in milliseconds. Converted to seconds with upward rounding during execution.
Timeout Support

The timeout will only take effect if both the DBMS and the JDBC driver support setQueryTimeout.

Query Examples

Fetching data from a database configured with the connection name mysql:

Example #1
db connection=mysql query="SELECT * FROM user_info.user;"

Updating data in a database configured with the connection name mysql. The result retains the data from the source command:

Example #2
db connection=mysql query="INSERT INTO user_info.user (name, email) VALUES ('James', 'james@email.org');"

Executing a command with a saved query. The query stored under the name mysql_query will be executed:

Example #3
db connection=mysql query=mysql_query

Example of a query to a database with time stamps:

Example #4
"SELECT * FROM user_info.user WHERE date_field >= {{_earliest}};"