SQLExecuteQueryOperator

Common SQL

Executes SQL code in a specific database :param sql: the SQL code or string pointing to a template file to be executed (templated). File must have a ‘.sql’ extensions.

View on GitHub

Last Updated: Mar. 7, 2023

Access Instructions

Install the Common SQL provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

autocommit(optional) if True, each command is automatically committed (default: False).
parameters(optional) the parameters to render the SQL query with.
handler(optional) the function that will be applied to the cursor (default: fetch_all_handler).
split_statements(optional) if split single SQL string into statements. By default, defers to the default value in the run method of the configured hook.
return_last(optional) return the result of only last statement (default: True).

Documentation

Executes SQL code in a specific database :param sql: the SQL code or string pointing to a template file to be executed (templated). File must have a ‘.sql’ extensions.

When implementing a specific Operator, you can also implement _process_output method in the hook to perform additional processing of values returned by the DB Hook of yours. For example, you can join description retrieved from the cursors of your statements with returned values, or save the output of your operator to a file.

See also

For more information on how to use this operator, take a look at the guide: Execute SQL query

Was this page helpful?