File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 22title : 切换数据库
33---
44
5- ::: tip
5+ ::: warning
66此教程仅适用于 PostgreSQL 用户
7+
8+ PostgreSQL 严格遵循 SQL 标准,很多类型实现和设计上都已远超 MySQL,后期我们将变更默认配置为 PostgreSQL
79:::
810
911fba 支持 MySQL、PostgreSQL 两种数据库,默认配置使用 MySQL
Original file line number Diff line number Diff line change @@ -60,3 +60,33 @@ return await self.select_order( # [!code word:noload]
6060` DETAIL: Key (id)=(x) already exists ` 的错误
6161
6262解决方案请自行浏览器搜索:如何重置 pg 主键序列?
63+
64+ ## 数据库时区陷阱
65+
66+ MySQL 不支持时区类型(数据库驱动设计便是如此),而 PostgreSQL 拥有完美的时区类型,以下是一个时区相关的经典案例
67+
68+ ::: chat title="群聊"
69+ {:2025-08-26 12:44:00}
70+
71+ {王}
72+ 请教大佬,为啥我查询的时间用的不同的时区和时间戳,返回的数据却是一样的?
73+
74+ ![ question_db_timezone] ( /images/question_db_timezone.png )
75+
76+ 数据库用的是 mysql,原则上这两个 datetime 的时间戳是不一样的,但是查出来的数据是一样的结果;
77+
78+ {王}
79+ 我直接写sql查询,这个两个是符合预期结果的,第一个有数据,第二个查不到;
80+
81+ ![ question_sql_timezone] ( /images/question_sql_timezone.png )
82+
83+ 这个切换到pg数据库后查询符合预期结果的;
84+
85+ {.}
86+ ** timezone** : not used by the MySQL dialect.
87+
88+ sqla 不处理 mysql 时区,即便换成 TIMESTAMP
89+
90+ {.}
91+ 更具体的:[ sqlalchemy/1985] ( https://github.com/sqlalchemy/sqlalchemy/issues/1985 )
92+ :::
You can’t perform that action at this time.
0 commit comments