airflow.providers.common.sql.hooks.handlers
¶
Module Contents¶
Functions¶
|
Determine when results of single query only should be returned. |
|
Return results for DbApiHook.run(). |
|
Return first result for DbApiHook.run(). |
- airflow.providers.common.sql.hooks.handlers.return_single_query_results(sql, return_last, split_statements)[source]¶
Determine when results of single query only should be returned.
For compatibility reasons, the behaviour of the DBAPIHook is somewhat confusing. In some cases, when multiple queries are run, the return value will be an iterable (list) of results – one for each query. However, in other cases, when single query is run, the return value will be just the result of that single query without wrapping the results in a list.
The cases when single query results are returned without wrapping them in a list are as follows:
sql is string and
return_last
is True (regardless whatsplit_statements
value is)sql is string and
split_statements
is False
In all other cases, the results are wrapped in a list, even if there is only one statement to process. In particular, the return value will be a list of query results in the following circumstances:
when
sql
is an iterable of string statements (regardless whatreturn_last
value is)when
sql
is string,split_statements
is True andreturn_last
is False
- Parameters
sql (str | collections.abc.Iterable[str]) – sql to run (either string or list of strings)
return_last (bool) – whether last statement output should only be returned
split_statements (bool | None) – whether to split string statements.
- Returns
True if the hook should return single query results