class documentation

class SelectLabelStyle(Enum): (source)

View In Hierarchy

Label style constants that may be passed to :meth:`_sql.Select.set_label_style`.

Constant LABEL_STYLE_DISAMBIGUATE_ONLY Label style indicating that columns with a name that conflicts with an existing name should be labeled with a semi-anonymizing label when generating the columns clause of a SELECT statement.
Constant LABEL_STYLE_LEGACY_ORM Undocumented
Constant LABEL_STYLE_NONE Label style indicating no automatic labeling should be applied to the columns clause of a SELECT statement.
Constant LABEL_STYLE_TABLENAME_PLUS_COL Label style indicating all columns should be labeled as ``<tablename>_<columnname>`` when generating the columns clause of a SELECT statement, to disambiguate same-named columns referenced from different tables, aliases, or subqueries.
LABEL_STYLE_DISAMBIGUATE_ONLY: int = (source)

Label style indicating that columns with a name that conflicts with an existing name should be labeled with a semi-anonymizing label when generating the columns clause of a SELECT statement. Below, most column names are left unaffected, except for the second occurrence of the name ``columna``, which is labeled using the label ``columna_1`` to disambiguate it from that of ``tablea.columna``: .. sourcecode:: pycon+sql >>> from sqlalchemy import table, column, select, true, LABEL_STYLE_DISAMBIGUATE_ONLY >>> table1 = table("table1", column("columna"), column("columnb")) >>> table2 = table("table2", column("columna"), column("columnc")) >>> print(select(table1, table2).join(table2, true()).set_label_style(LABEL_STYLE_DISAMBIGUATE_ONLY)) {printsql}SELECT table1.columna, table1.columnb, table2.columna AS columna_1, table2.columnc FROM table1 JOIN table2 ON true Used with the :meth:`_sql.GenerativeSelect.set_label_style` method, :data:`_sql.LABEL_STYLE_DISAMBIGUATE_ONLY` is the default labeling style for all SELECT statements outside of :term:`1.x style` ORM queries. .. versionadded:: 1.4

Value
2
LABEL_STYLE_LEGACY_ORM: int = (source)

Undocumented

Value
3
LABEL_STYLE_NONE: int = (source)

Label style indicating no automatic labeling should be applied to the columns clause of a SELECT statement. Below, the columns named ``columna`` are both rendered as is, meaning that the name ``columna`` can only refer to the first occurrence of this name within a result set, as well as if the statement were used as a subquery: .. sourcecode:: pycon+sql >>> from sqlalchemy import table, column, select, true, LABEL_STYLE_NONE >>> table1 = table("table1", column("columna"), column("columnb")) >>> table2 = table("table2", column("columna"), column("columnc")) >>> print(select(table1, table2).join(table2, true()).set_label_style(LABEL_STYLE_NONE)) {printsql}SELECT table1.columna, table1.columnb, table2.columna, table2.columnc FROM table1 JOIN table2 ON true Used with the :meth:`_sql.Select.set_label_style` method. .. versionadded:: 1.4

Value
0
LABEL_STYLE_TABLENAME_PLUS_COL: int = (source)

Label style indicating all columns should be labeled as ``<tablename>_<columnname>`` when generating the columns clause of a SELECT statement, to disambiguate same-named columns referenced from different tables, aliases, or subqueries. Below, all column names are given a label so that the two same-named columns ``columna`` are disambiguated as ``table1_columna`` and ``table2_columna``: .. sourcecode:: pycon+sql >>> from sqlalchemy import table, column, select, true, LABEL_STYLE_TABLENAME_PLUS_COL >>> table1 = table("table1", column("columna"), column("columnb")) >>> table2 = table("table2", column("columna"), column("columnc")) >>> print(select(table1, table2).join(table2, true()).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)) {printsql}SELECT table1.columna AS table1_columna, table1.columnb AS table1_columnb, table2.columna AS table2_columna, table2.columnc AS table2_columnc FROM table1 JOIN table2 ON true Used with the :meth:`_sql.GenerativeSelect.set_label_style` method. Equivalent to the legacy method ``Select.apply_labels()``; :data:`_sql.LABEL_STYLE_TABLENAME_PLUS_COL` is SQLAlchemy's legacy auto-labeling style. :data:`_sql.LABEL_STYLE_DISAMBIGUATE_ONLY` provides a less intrusive approach to disambiguation of same-named column expressions. .. versionadded:: 1.4

Value
1