Sqlx, possible to use sql's "NOW()"

⚓ rust    📅 2025-06-18    👤 surdeus    👁️ 2      

surdeus

I have a field that holds a timestamp.

I'm inserting with two different queries, one that doesn't contain the field on the list of data being inserted, to abuse the DEFAULT NOW() on that field, but the ideal solution would be something like:

let mytime: Option<sqlx::types::time::OffsetDateTime> = ...;
let db_result = sqlx::query("INSERT INTO
        table (mytimestamp)
        VALUES   ($1);")
.bind(mytime.or(sqlx::something::now))

Is there any way to tell sqlx that I want a value of a function call?

5 posts - 3 participants

Read full topic

🏷️ rust_feed