airflow.providers.common.sql.hooks.handlers¶
Functions¶
|
Determine when results of single query only should be returned. |
|
Return results for DbApiHook.run(). |
|
Return first result for DbApiHook.run(). |
Module Contents¶
- 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_lastis True (regardless whatsplit_statementsvalue is)sql is string and
split_statementsis 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
sqlis an iterable of string statements (regardless whatreturn_lastvalue is)when
sqlis string,split_statementsis True andreturn_lastis 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
- Return type: