class SQLCompiler(Compiled):
Known subclasses: sqlalchemy.sql.compiler.StrSQLCompiler
, sqlalchemy.databases.firebird.FBCompiler
, sqlalchemy.databases.mssql.MSSQLCompiler
, sqlalchemy.databases.mysql.MySQLCompiler
, sqlalchemy.databases.oracle.OracleCompiler
, sqlalchemy.databases.postgresql.PGCompiler
, sqlalchemy.databases.sqlite.SQLiteCompiler
, sqlalchemy.databases.sybase.SybaseSQLCompiler
Default implementation of .Compiled
.
Compiles _expression.ClauseElement
objects into SQL strings.
Method | __init__ |
Construct a new .SQLCompiler object. |
Method | construct_params |
return a dictionary of bind parameter keys and values |
Method | default_from |
Called when a SELECT statement has no froms, and no FROM clause is to be appended. |
Method | delete_extra_from_clause |
Provide a hook to override the generation of an DELETE..FROM clause. |
Method | get_select_precolumns |
Called when building a SELECT statement, position is just before column list. |
Method | group_by_clause |
allow dialects to customize how GROUP BY is rendered. |
Method | order_by_clause |
allow dialects to customize how ORDER BY is rendered. |
Method | render_literal_value |
Render the value of a bind parameter as a quoted literal. |
Method | update_from_clause |
Provide a hook to override the generation of an UPDATE..FROM clause. |
Method | update_limit_clause |
Provide a hook for MySQL to add LIMIT to the UPDATE |
Method | update_tables_clause |
Provide a hook to override the initial table clause in an UPDATE statement. |
Class Variable | ansi_bind_rules |
No summary |
Class Variable | insert_single_values_expr |
When an INSERT is compiled with a single set of parameters inside a VALUES expression, the string is assigned here, where it can be used for insert batching schemes to rewrite the VALUES expression. |
Class Variable | literal_execute_params |
bindparameter objects that are rendered as literal values at statement execution time. |
Class Variable | postfetch_lastrowid |
if True, and this in insert, use cursor.lastrowid to populate result.inserted_primary_key. |
Class Variable | render_table_with_column_in_update_from |
set to True classwide to indicate the SET clause in a multi-table UPDATE statement should qualify columns with the table name (i.e. MySQL only) |
Class Variable | returning_precedes_values |
set to True classwide to generate RETURNING clauses before the VALUES or WHERE clause (i.e. MSSQL) |
Class Variable | translate_select_structure |
if not None, should be a callable which accepts (select_stmt, **kw) and returns a select object. this is used for structural changes mostly to accommodate for LIMIT/OFFSET schemes |
Instance Variable | escaped_bind_names |
Undocumented |
Instance Variable | has_out_parameters |
if True, there are bindparam() objects that have the isoutparam flag set. |
Instance Variable | isdelete |
Undocumented |
Instance Variable | positiontup |
for a compiled construct that uses a positional paramstyle, will be a sequence of strings, indicating the names of bound parameters in order. |
Instance Variable | post_compile_params |
bindparameter objects that are rendered as bound parameter placeholders at statement execution time. |
Instance Variable | returning |
holds the "returning" collection of columns if the statement is CRUD and defines returning columns either implicitly or explicitly |
Method | _add_to_result_map |
Undocumented |
Method | _anonymize |
Undocumented |
Method | _apply_numbered_params |
Undocumented |
Method | _compose_select_body |
Undocumented |
Method | _create_result_map |
utility method used for unit tests only. |
Method | _display_froms_for_select |
Undocumented |
Method | _fallback_column_name |
Undocumented |
Method | _format_frame_clause |
Undocumented |
Method | _generate_delimited_and_list |
Undocumented |
Method | _generate_delimited_list |
Undocumented |
Method | _generate_generic_binary |
Undocumented |
Method | _generate_generic_unary_modifier |
Undocumented |
Method | _generate_generic_unary_operator |
Undocumented |
Method | _generate_prefixes |
Undocumented |
Method | _get_operator_dispatch |
Undocumented |
Method | _get_set_input_sizes_lookup |
Undocumented |
Method | _init_cte_state |
Initialize collections related to CTEs only if a CTE is located, to save on the overhead of these collections otherwise. |
Method | _label_returning_column |
Render a column with necessary labels inside of a RETURNING clause. |
Method | _label_select_column |
produce labeled columns present in a select(). |
Method | _literal_execute_expanding_parameter |
Undocumented |
Method | _literal_execute_expanding_parameter_literal_binds |
Undocumented |
Method | _nested_result |
special API to support the use case of 'nested result sets' |
Method | _process_parameters_for_postcompile |
handle special post compile parameters. |
Method | _render_cte_clause |
No summary |
Method | _row_limit_clause |
Undocumented |
Method | _setup_crud_hints |
Undocumented |
Method | _setup_select_hints |
Undocumented |
Method | _setup_select_stack |
Undocumented |
Method | _truncate_bindparam |
Undocumented |
Method | _truncated_identifier |
Undocumented |
Method | bindparam_string |
Undocumented |
Method | delete_table_clause |
Undocumented |
Method | escape_literal_column |
Undocumented |
Method | fetch_clause |
Undocumented |
Method | for_update_clause |
Undocumented |
Method | format_from_hint_text |
Undocumented |
Method | function_argspec |
Undocumented |
Method | get_crud_hint_text |
Undocumented |
Method | get_cte_preamble |
Undocumented |
Method | get_from_hint_text |
Undocumented |
Method | get_render_as_alias_suffix |
Undocumented |
Method | get_select_hint_text |
Undocumented |
Method | get_statement_hint_text |
Undocumented |
Method | is_subquery |
Undocumented |
Method | limit_clause |
Undocumented |
Method | post_process_text |
Undocumented |
Method | render_literal_bindparam |
Undocumented |
Method | returning_clause |
Undocumented |
Method | visit_alias |
Undocumented |
Method | visit_between_op_binary |
Undocumented |
Method | visit_binary |
Undocumented |
Method | visit_bindparam |
Undocumented |
Method | visit_case |
Undocumented |
Method | visit_cast |
Undocumented |
Method | visit_clauselist |
Undocumented |
Method | visit_collation |
Undocumented |
Method | visit_column |
Undocumented |
Method | visit_compound_select |
Undocumented |
Method | visit_contains_op_binary |
Undocumented |
Method | visit_cte |
Undocumented |
Method | visit_custom_op_binary |
Undocumented |
Method | visit_custom_op_unary_modifier |
Undocumented |
Method | visit_custom_op_unary_operator |
Undocumented |
Method | visit_delete |
Undocumented |
Method | visit_empty_set_expr |
Undocumented |
Method | visit_empty_set_op_expr |
Undocumented |
Method | visit_endswith_op_binary |
Undocumented |
Method | visit_extract |
Undocumented |
Method | visit_false |
Undocumented |
Method | visit_fromclause |
Undocumented |
Method | visit_funcfilter |
Undocumented |
Method | visit_function |
Undocumented |
Method | visit_function_as_comparison_op_binary |
Undocumented |
Method | visit_grouping |
Undocumented |
Method | visit_ilike_op_binary |
Undocumented |
Method | visit_index |
Undocumented |
Method | visit_insert |
Undocumented |
Method | visit_is_false_unary_operator |
Undocumented |
Method | visit_is_true_unary_operator |
Undocumented |
Method | visit_join |
Undocumented |
Method | visit_label |
Undocumented |
Method | visit_label_reference |
Undocumented |
Method | visit_lambda_element |
Undocumented |
Method | visit_lateral |
Undocumented |
Method | visit_like_op_binary |
Undocumented |
Method | visit_mod_binary |
Undocumented |
Method | visit_next_value_func |
Undocumented |
Method | visit_not_between_op_binary |
Undocumented |
Method | visit_not_contains_op_binary |
Undocumented |
Method | visit_not_endswith_op_binary |
Undocumented |
Method | visit_not_ilike_op_binary |
Undocumented |
Method | visit_not_in_op_binary |
Undocumented |
Method | visit_not_like_op_binary |
Undocumented |
Method | visit_not_match_op_binary |
Undocumented |
Method | visit_not_regexp_match_op_binary |
Undocumented |
Method | visit_not_startswith_op_binary |
Undocumented |
Method | visit_null |
Undocumented |
Method | visit_over |
Undocumented |
Method | visit_regexp_match_op_binary |
Undocumented |
Method | visit_regexp_replace_op_binary |
Undocumented |
Method | visit_release_savepoint |
Undocumented |
Method | visit_rollback_to_savepoint |
Undocumented |
Method | visit_savepoint |
Undocumented |
Method | visit_scalar_function_column |
Undocumented |
Method | visit_select |
Undocumented |
Method | visit_select_statement_grouping |
Undocumented |
Method | visit_sequence |
Undocumented |
Method | visit_startswith_op_binary |
Undocumented |
Method | visit_subquery |
Undocumented |
Method | visit_table |
Undocumented |
Method | visit_table_valued_alias |
Undocumented |
Method | visit_table_valued_column |
Undocumented |
Method | visit_tablesample |
Undocumented |
Method | visit_textclause |
Undocumented |
Method | visit_textual_label_reference |
Undocumented |
Method | visit_textual_select |
Undocumented |
Method | visit_true |
Undocumented |
Method | visit_tuple |
Undocumented |
Method | visit_type_coerce |
Undocumented |
Method | visit_typeclause |
Undocumented |
Method | visit_unary |
Undocumented |
Method | visit_update |
Undocumented |
Method | visit_values |
Undocumented |
Method | visit_withingroup |
Undocumented |
Class Variable | _default_stack_entry |
Undocumented |
Class Variable | insert_prefetch |
Undocumented |
Class Variable | update_prefetch |
Undocumented |
Instance Variable | _cache_key_bind_match |
a mapping that will relate the BindParameter object we compile to those that are part of the extracted collection of parameters in the cache key, if we were given a cache key. |
Instance Variable | _loose_column_name_matching |
tell the result object that the SQL statement is textual, wants to match up to Column objects, and may be using the ._tq_label in the SELECT rather than the base name. |
Instance Variable | _numeric_binds |
True if paramstyle is "numeric". This paramstyle is trickier than all the others. |
Instance Variable | _ordered_columns |
if False, means we can't be sure the list of entries in _result_columns is actually the rendered order. Usually True unless using an unordered TextualSelect. |
Instance Variable | _render_postcompile |
whether to render out POSTCOMPILE params during the compile phase. |
Instance Variable | _result_columns |
Undocumented |
Instance Variable | _textual_ordered_columns |
tell the result object that the column names as rendered are important, but they are also "ordered" vs. what is in the compiled object here. |
Instance Variable | anon_map |
Undocumented |
Instance Variable | bind_names |
Undocumented |
Instance Variable | binds |
Undocumented |
Instance Variable | bindtemplate |
Undocumented |
Instance Variable | cache_key |
Undocumented |
Instance Variable | column_keys |
Undocumented |
Instance Variable | compile_state |
Optional .CompileState object that maintains additional state used by the compiler. |
Instance Variable | cte_positional |
Undocumented |
Instance Variable | ctes |
Undocumented |
Instance Variable | ctes_by_level_name |
Undocumented |
Instance Variable | ctes_recursive |
Undocumented |
Instance Variable | execution_options |
Undocumented |
Instance Variable | for_executemany |
Undocumented |
Instance Variable | from_linter |
Undocumented |
Instance Variable | inline |
Undocumented |
Instance Variable | isinsert |
Undocumented |
Instance Variable | isplaintext |
Undocumented |
Instance Variable | isupdate |
class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE |
Instance Variable | label_length |
Undocumented |
Instance Variable | level_name_by_cte |
Undocumented |
Instance Variable | linting |
Undocumented |
Instance Variable | positional |
Undocumented |
Instance Variable | stack |
Undocumented |
Instance Variable | string |
Undocumented |
Instance Variable | truncated_names |
Undocumented |
Property | _bind_processors |
Undocumented |
Property | _global_attributes |
Undocumented |
Property | _inserted_primary_key_from_lastrowid_getter |
Undocumented |
Property | _inserted_primary_key_from_returning_getter |
Undocumented |
Property | _like_percent_literal |
Undocumented |
Property | current_executable |
Return the current 'executable' that is being compiled. |
Property | params |
Return the bind param dictionary embedded into this compiled object, for those values that are present. |
Property | prefetch |
Undocumented |
Property | sql_compiler |
Return a Compiled that is capable of processing SQL expressions. |
Inherited from Compiled
:
Method | __str__ |
Return the string text of the generated SQL or DDL. |
Method | _execute_on_connection |
Undocumented |
Method | process |
Undocumented |
Method | visit_unsupported_compilation |
Undocumented |
Class Variable | _cached_metadata |
Undocumented |
Instance Variable | _annotations |
Undocumented |
Instance Variable | _gen_time |
Undocumented |
Instance Variable | can_execute |
Undocumented |
Instance Variable | dialect |
Undocumented |
Instance Variable | preparer |
Undocumented |
Instance Variable | schema_translate_map |
Undocumented |
Instance Variable | statement |
Undocumented |
.SQLCompiler
object.Parameters | |
dialect | .Dialect to be used |
statement | _expression.ClauseElement to be compiled |
cache_key | Undocumented |
column_keys | a list of column names to be compiled into an INSERT or UPDATE statement. |
for_executemany | whether INSERT / UPDATE statements should expect that they are to be invoked in an "executemany" style, which may impact how the statement will be expected to return the values of defaults and autoincrement / sequences and similar. Depending on the backend and driver in use, support for retrieving these values may be disabled which means SQL expressions may be rendered inline, RETURNING may not be rendered, etc. |
linting | Undocumented |
**kwargs | additional keyword arguments to be consumed by the superclass. |
sqlalchemy.databases.firebird.FBCompiler
, sqlalchemy.databases.mysql.MySQLCompiler
, sqlalchemy.databases.oracle.OracleCompiler
Called when a SELECT statement has no froms, and no FROM clause is to be appended.
Gives Oracle a chance to tack on a FROM DUAL to the string output.
sqlalchemy.sql.compiler.StrSQLCompiler
, sqlalchemy.databases.mssql.MSSQLCompiler
, sqlalchemy.databases.mysql.MySQLCompiler
, sqlalchemy.databases.postgresql.PGCompiler
, sqlalchemy.databases.sybase.SybaseSQLCompiler
Provide a hook to override the generation of an DELETE..FROM clause.
This can be used to implement DELETE..USING for example.
MySQL and MSSQL override this.
sqlalchemy.databases.firebird.FBCompiler
, sqlalchemy.databases.mssql.MSSQLCompiler
, sqlalchemy.databases.mysql.MySQLCompiler
, sqlalchemy.databases.postgresql.PGCompiler
sqlalchemy.databases.mssql.MSSQLCompiler
, sqlalchemy.databases.sybase.SybaseSQLCompiler
sqlalchemy.databases.mssql.MSSQLStrictCompiler
, sqlalchemy.databases.mysql.MySQLCompiler
, sqlalchemy.databases.postgresql.PGCompiler
Render the value of a bind parameter as a quoted literal.
This is used for statement sections that do not accept bind parameters on the target driver/database.
This should be implemented by subclasses using the quoting services of the DBAPI.
sqlalchemy.sql.compiler.StrSQLCompiler
, sqlalchemy.databases.mssql.MSSQLCompiler
, sqlalchemy.databases.mysql.MySQLCompiler
, sqlalchemy.databases.postgresql.PGCompiler
Provide a hook to override the generation of an UPDATE..FROM clause.
MySQL and MSSQL override this.
sqlalchemy.databases.mysql.MySQLCompiler
sqlalchemy.databases.mysql.MySQLCompiler
Provide a hook to override the initial table clause in an UPDATE statement.
MySQL overrides this.
bool
=
sqlalchemy.databases.firebird.FBCompiler
, sqlalchemy.databases.mssql.MSSQLStrictCompiler
, sqlalchemy.databases.sybase.SybaseSQLCompiler
When an INSERT is compiled with a single set of parameters inside a VALUES expression, the string is assigned here, where it can be used for insert batching schemes to rewrite the VALUES expression.
bool
=
bool
=
sqlalchemy.databases.mysql.MySQLCompiler
bool
=
sqlalchemy.databases.mssql.MSSQLCompiler
bool
=
sqlalchemy.databases.oracle.OracleCompiler
for a compiled construct that uses a positional paramstyle, will be a sequence of strings, indicating the names of bound parameters in order.
This is used in order to render bound parameters in their correct order,
and is combined with the _sql.Compiled.params
dictionary to
render parameters.
See Also
:ref:`faq_sql_expression_string` - includes a usage example for debugging use cases.
Undocumented
sqlalchemy.sql.compiler.StrSQLCompiler
Undocumented
Undocumented
Render a column with necessary labels inside of a RETURNING clause.
This method is provided for individual dialects in place of calling the _label_select_column method directly, so that the two use cases of RETURNING vs. SELECT can be disambiguated going forward.
handle special post compile parameters.
These include:
sqlalchemy.databases.mssql.MSSQLCompiler
Undocumented
Undocumented
sqlalchemy.databases.postgresql.PGCompiler
Undocumented
sqlalchemy.databases.mssql.MSSQLCompiler
Undocumented
sqlalchemy.databases.oracle.OracleCompiler
Undocumented
sqlalchemy.databases.oracle.OracleCompiler
Undocumented
sqlalchemy.databases.firebird.FBCompiler
, sqlalchemy.databases.mssql.MSSQLCompiler
, sqlalchemy.databases.mysql.MySQLCompiler
, sqlalchemy.databases.oracle.OracleCompiler
, sqlalchemy.databases.postgresql.PGCompiler
, sqlalchemy.databases.sqlite.SQLiteCompiler
, sqlalchemy.databases.sybase.SybaseSQLCompiler
Undocumented
Undocumented
sqlalchemy.databases.mssql.MSSQLCompiler
Undocumented
Undocumented
sqlalchemy.databases.mssql.MSSQLCompiler
Undocumented
Undocumented
sqlalchemy.databases.sqlite.SQLiteCompiler
Undocumented
sqlalchemy.databases.oracle.OracleCompiler
Undocumented
sqlalchemy.databases.postgresql.PGCompiler
Undocumented
Undocumented
sqlalchemy.databases.postgresql.PGCompiler
Undocumented
sqlalchemy.databases.mssql.MSSQLStrictCompiler
Undocumented
sqlalchemy.databases.firebird.FBCompiler
Undocumented
sqlalchemy.databases.mssql.MSSQLCompiler
Undocumented
sqlalchemy.databases.mssql.MSSQLCompiler
Undocumented
Undocumented
sqlalchemy.databases.firebird.FBCompiler
Undocumented
sqlalchemy.databases.mssql.MSSQLCompiler
Undocumented
sqlalchemy.databases.oracle.OracleCompiler
Undocumented
Undocumented
sqlalchemy.databases.mysql.MySQLCompiler
Undocumented
bool
=
bool
=
Optional .CompileState
object that maintains additional
state used by the compiler.
Major executable objects such as _expression.Insert
,
_expression.Update
, _expression.Delete
,
_expression.Select
will generate this
state when compiled in order to calculate additional information about the
object. For the top level object that is to be executed, the state can be
stored here where it can also have applicability towards result set
processing.
bool
=
Undocumented
Undocumented
Return the current 'executable' that is being compiled.
This is currently the _sql.Select
, _sql.Insert
,
_sql.Update
, _sql.Delete
,
_sql.CompoundSelect
object that is being compiled.
Specifically it's assigned to the self.stack list of elements.
When a statement like the above is being compiled, it normally
is also assigned to the .statement attribute of the
_sql.Compiler
object. However, all SQL constructs are
ultimately nestable, and this attribute should never be consulted
by a visit_ method, as it is not guaranteed to be assigned
nor guaranteed to correspond to the current statement being compiled.
New in version 1.3.21: For compatibility with previous versions, use the following recipe:
statement = getattr(self, "current_executable", False) if statement is False: statement = self.stack[-1]["selectable"]
For versions 1.4 and above, ensure only .current_executable is used; the format of "self.stack" may change.
sqlalchemy.sql.compiler.Compiled.params
Return the bind param dictionary embedded into this compiled object, for those values that are present.
See Also
:ref:`faq_sql_expression_string` - includes a usage example for debugging use cases.