Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression. :func:`.nulls_first` is intended to modify the expression produced by :func:`.asc` or :func:`.desc`, and indicates how NULL values should be handled when they are encountered during ordering:: from sqlalchemy
(column: _ColumnExpressionArgument[_T])
| 1320 | |
| 1321 | |
| 1322 | def nulls_first(column: _ColumnExpressionArgument[_T]) -> UnaryExpression[_T]: |
| 1323 | """Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression. |
| 1324 | |
| 1325 | :func:`.nulls_first` is intended to modify the expression produced |
| 1326 | by :func:`.asc` or :func:`.desc`, and indicates how NULL values |
| 1327 | should be handled when they are encountered during ordering:: |
| 1328 | |
| 1329 | |
| 1330 | from sqlalchemy import desc, nulls_first |
| 1331 | |
| 1332 | stmt = select(users_table).order_by(nulls_first(desc(users_table.c.name))) |
| 1333 | |
| 1334 | The SQL expression from the above would resemble: |
| 1335 | |
| 1336 | .. sourcecode:: sql |
| 1337 | |
| 1338 | SELECT id, name FROM user ORDER BY name DESC NULLS FIRST |
| 1339 | |
| 1340 | Like :func:`.asc` and :func:`.desc`, :func:`.nulls_first` is typically |
| 1341 | invoked from the column expression itself using |
| 1342 | :meth:`_expression.ColumnElement.nulls_first`, |
| 1343 | rather than as its standalone |
| 1344 | function version, as in:: |
| 1345 | |
| 1346 | stmt = select(users_table).order_by( |
| 1347 | users_table.c.name.desc().nulls_first() |
| 1348 | ) |
| 1349 | |
| 1350 | .. versionchanged:: 1.4 :func:`.nulls_first` is renamed from |
| 1351 | :func:`.nullsfirst` in previous releases. |
| 1352 | The previous name remains available for backwards compatibility. |
| 1353 | |
| 1354 | .. seealso:: |
| 1355 | |
| 1356 | :func:`.asc` |
| 1357 | |
| 1358 | :func:`.desc` |
| 1359 | |
| 1360 | :func:`.nulls_last` |
| 1361 | |
| 1362 | :meth:`_expression.Select.order_by` |
| 1363 | |
| 1364 | """ # noqa: E501 |
| 1365 | return UnaryExpression._create_nulls_first(column) |
| 1366 | |
| 1367 | |
| 1368 | def nulls_last(column: _ColumnExpressionArgument[_T]) -> UnaryExpression[_T]: |
nothing calls this directly
no test coverage detected