pub trait NullOrder {
const NULLS: NullOrdering;
}sqlx only.Expand description
How one SQL dialect reaches pinned_nulls.
A CONST rather than a rendering method, for the reason QuoteIdent::QUOTE and
BindCeiling::MAX_BIND_PARAMETERS are: the answer is the whole of what the dialects differ in,
while what to do with it — render nothing, render the clause, or refuse — is one rule everywhere.
§The measurement
| dialect | default on ASC | default on DESC | NULLS FIRST / NULLS LAST | answer |
|---|---|---|---|---|
| SQLite 3.51.0 | first | last | yes, since 3.30 | Implicit |
| MySQL 8.4.11 | first | last | no — ERROR 1064, a syntax error | Implicit |
| PostgreSQL 16.14, 17.10 | last | first | yes | Explicit |
§Why the pin is the position two dialects already have, and not Postgres’s
It is the only pinning every shipped dialect can express. Under the other one — NULL above
every value, which is Postgres’s own default — MySQL can express nothing: it has no clause, so
the position would have to be reached by an IS NULL PREFIX TERM (ORDER BY (a IS NULL), a),
and that is not a modifier on the term but an EXTRA TERM. It is a column the keyset expansion’s
own list does not contain, so the ordering and the comparison would be over two different
tuples; it is a derived expression, so no index over the column serves the order; and it is
invisible in the cursor, so nothing would notice the disagreement. Measured to answer correctly
on MySQL 8.4.11 — the SQL works, and it is the wrong shape for this seam.
The pin chosen instead costs SQLite and MySQL nothing at all: their ordering terms render exactly as they did, and an index over the bare column still serves them. Postgres states the clause, which is a modifier on the term rather than a term of its own — so the tuple the ordering runs over is still the tuple the cursor holds.
Required Associated Constants§
Sourceconst NULLS: NullOrdering
const NULLS: NullOrdering
This dialect’s answer.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl NullOrder for MySql
Available on crate feature mysql only.Measured on MySQL 8.4.11: NULL leads an ascending term and trails a descending one, which is
the framework’s own position — so a term states nothing, which is fortunate, because
NULLS LAST there is ERROR 1064 and not a clause at all.
impl NullOrder for MySql
mysql only.Measured on MySQL 8.4.11: NULL leads an ascending term and trails a descending one, which is
the framework’s own position — so a term states nothing, which is fortunate, because
NULLS LAST there is ERROR 1064 and not a clause at all.
const NULLS: NullOrdering = NullOrdering::Implicit
Source§impl NullOrder for Postgres
Available on crate feature postgres only.Measured on PostgreSQL 16.14 and 17.10: NULL TRAILS an ascending term and leads a descending
one — the opposite of the framework’s position, and the one dialect of the three that differs. It
has the clause, so the position is stated on the term.
impl NullOrder for Postgres
postgres only.Measured on PostgreSQL 16.14 and 17.10: NULL TRAILS an ascending term and leads a descending
one — the opposite of the framework’s position, and the one dialect of the three that differs. It
has the clause, so the position is stated on the term.
The cost is an INDEX one and belongs to DDL rather than here: a default btree index is built
NULLS LAST on ascending, so an ordering that asks for NULLS FIRST is served by an index
declared to match. Nothing in this crate emits DDL, and the alternative — following the dialect
rather than the framework — is the disagreement between the ordering and the cursor that
NullOrdering::Inexpressible exists to refuse rather than to hide.
const NULLS: NullOrdering = NullOrdering::Explicit
Source§impl NullOrder for Sqlite
Available on crate feature sqlite only.Measured on SQLite 3.51.0: NULL leads an ascending term and trails a descending one, which is
the framework’s own position, so a term states nothing. NULLS FIRST / NULLS LAST exist since
3.30 and are not needed here.
impl NullOrder for Sqlite
sqlite only.Measured on SQLite 3.51.0: NULL leads an ascending term and trails a descending one, which is
the framework’s own position, so a term states nothing. NULLS FIRST / NULLS LAST exist since
3.30 and are not needed here.