I have found these related issues/pull requests
I searched by TIMESTAMP and UnexpectedNull, did not found anything related.
Description
mysql TIMESTAMP, when defined as
CREATE TABLE events (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
is by default not nullable.
> show create table events;
...
`created_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
...
It can contain a "zero" value.
When so, the query_as! fails with UnexpectedNullError.
I think this is due to "zero" value semantically having similar meaning to "missing" (= NULL).
SQLX looks at the type received from the database when generating the query by the macro. The database says its not nullable.
However, when doing insert like this:
INSERT INTO events VALUES ();
it will have the updated_at value equal to 0000-00-00 00:00:00 (= 0).
I am not really profficient with sqlx codebase, but it may be due to this guy returning it as None, and this transforming it into an error.
I am however not sure what this should return, if anything. Changing the return type is probably a no go?
Always considering the TIMESTAMP as Option<...> would work, but I think (not sure) the behavior with the "zero" value can be turned off, so it doesn't always make sense.
I think at least adding a small note to sqlx-mysql/types/mod.rs would help.
Reproduction steps
https://github.com/gregofi/sqlx-mysql-timestamp/
- Run
docker compose up
- Run
cargo run, should panic at runtime.
SQLx version
0.9
Enabled SQLx features
mysql, chrono, macros, runtime-tokio
Database server and version
mariadb 10.5
Operating system
Linux
Rust version
rustc 1.95.0 (59807616e 2026-04-14)
I have found these related issues/pull requests
I searched by TIMESTAMP and UnexpectedNull, did not found anything related.
Description
mysql
TIMESTAMP, when defined asis by default not nullable.
It can contain a "zero" value.
When so, the
query_as!fails withUnexpectedNullError.I think this is due to "zero" value semantically having similar meaning to "missing" (= NULL).
SQLX looks at the type received from the database when generating the query by the macro. The database says its not nullable.
However, when doing insert like this:
it will have the
updated_atvalue equal to0000-00-00 00:00:00(= 0).I am not really profficient with sqlx codebase, but it may be due to this guy returning it as
None, and this transforming it into an error.I am however not sure what this should return, if anything. Changing the return type is probably a no go?
Always considering the TIMESTAMP as
Option<...>would work, but I think (not sure) the behavior with the "zero" value can be turned off, so it doesn't always make sense.I think at least adding a small note to
sqlx-mysql/types/mod.rswould help.Reproduction steps
https://github.com/gregofi/sqlx-mysql-timestamp/
docker compose upcargo run, should panic at runtime.SQLx version
0.9
Enabled SQLx features
mysql, chrono, macros, runtime-tokio
Database server and version
mariadb 10.5
Operating system
Linux
Rust version
rustc 1.95.0 (59807616e 2026-04-14)