< 返回版块

zzl221000 发表于 2024-06-07 20:04

Tags:sqlx,postgres

下面这个程序在mysql和sqlite上都没问题,但是postgres就会报错。

create qcc_company(id varchar(32) primary key,name text,to_time timestamp);
 sqlx::query("insert into qcc_company(id,name,to_time) values($1,$2,$3);")
            .bind("1234")
            .bind("test")
            .bind(None::<String>)
            .execute(&pool)
            .await?;

执行后就出现下面的报错

column "to_time" is of type timestamp without time zone but expression is of type text

有没有办法表示任意类型的null

这是在写一个工具从jsonline导入数据库,根据json自动生成sql写入,mysql和sqlite都搞定了,pg这里卡了好久

评论区

写评论
作者 zzl221000 2024-06-11 10:56

我看了下pg规范,null是有类型的,不像sqlite和mysql,null是独立的类型

--
👇
Bai-Jinlin: sqlx里面包了时间类型https://docs.rs/sqlx/latest/sqlx/types/chrono/index.html

Bai-Jinlin 2024-06-08 11:40

sqlx里面包了时间类型https://docs.rs/sqlx/latest/sqlx/types/chrono/index.html

1 共 2 条评论, 1 页