MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / desc

Function desc

lib/sqlalchemy/sql/_elements_constructors.py:1069–1109  ·  view source on GitHub ↗

Produce a descending ``ORDER BY`` clause element. e.g.:: from sqlalchemy import desc stmt = select(users_table).order_by(desc(users_table.c.name)) will produce SQL as: .. sourcecode:: sql SELECT id, name FROM user ORDER BY name DESC The :func:`.desc` fu

(
    column: _ColumnExpressionOrStrLabelArgument[_T],
)

Source from the content-addressed store, hash-verified

1067
1068
1069def desc(
1070 column: _ColumnExpressionOrStrLabelArgument[_T],
1071) -> UnaryExpression[_T]:
1072 """Produce a descending ``ORDER BY`` clause element.
1073
1074 e.g.::
1075
1076 from sqlalchemy import desc
1077
1078 stmt = select(users_table).order_by(desc(users_table.c.name))
1079
1080 will produce SQL as:
1081
1082 .. sourcecode:: sql
1083
1084 SELECT id, name FROM user ORDER BY name DESC
1085
1086 The :func:`.desc` function is a standalone version of the
1087 :meth:`_expression.ColumnElement.desc`
1088 method available on all SQL expressions,
1089 e.g.::
1090
1091
1092 stmt = select(users_table).order_by(users_table.c.name.desc())
1093
1094 :param column: A :class:`_expression.ColumnElement` (e.g.
1095 scalar SQL expression)
1096 with which to apply the :func:`.desc` operation.
1097
1098 .. seealso::
1099
1100 :func:`.asc`
1101
1102 :func:`.nulls_first`
1103
1104 :func:`.nulls_last`
1105
1106 :meth:`_expression.Select.order_by`
1107
1108 """
1109 return UnaryExpression._create_desc(column)
1110
1111
1112def distinct(expr: _ColumnExpressionArgument[_T]) -> UnaryExpression[_T]:

Callers 15

test_reflectMethod · 0.90
test_order_by_labelMethod · 0.90
test_order_byMethod · 0.90
test_order_by_nullsMethod · 0.90
test_orderby_subqueryMethod · 0.90
test_query_oneMethod · 0.90
test_statefulMethod · 0.90

Calls 1

_create_descMethod · 0.80

Tested by 15

test_reflectMethod · 0.72
test_order_by_labelMethod · 0.72
test_order_byMethod · 0.72
test_order_by_nullsMethod · 0.72
test_orderby_subqueryMethod · 0.72
test_query_oneMethod · 0.72
test_statefulMethod · 0.72
test_aliased_order_byMethod · 0.72