I have a table
CREATE TYPE WEEKDAY AS ENUM (
'sunday',
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday'
);
CREATE TABLE tasks
(
weekday WEEKDAY ARRAY
);
Following the documentation and other SO questions, I'd expect the following to work
#[derive(sqlx::Type)]
#[sqlx(type_name = "weekday", rename_all = "lowercase")]
enum Weekday {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
let weekday: Vec<Weekday> = Vec::new();
sqlx::query!(
r##"
INSERT INTO tasks (weekday)
VALUES ($1);
"##,
weekday
)
.execute(&mut **db)
.await
.expect("db failure");
but I get error error: unsupported type _weekday for param #1. I've tried to put as "weekday: weekday" in various places (as suggested in other threads), but always was responded with syntax error. How can I make it work?
Argh, after some digging I found the ugly answer.
weekday as Vec<Weekday>)PgHasArrayType- should be derivable bysqlx::Type, but enums are not supported at this momentso in summary the code is