[英]Casting and MySQL to Postgres migration
We're in the process of migrating from MySQL to Postgres and have come across a few queries that we're struggling with a little:我们正在从 MySQL 迁移到 Postgres,并且遇到了一些我们正在努力解决的查询:
MySQL: MySQL:
MAX(groups.id) IS NOT NULL AND MIN(groups.parent_id IS NULL) as parent_type
Postgres: Postgres:
(MAX(groups.id) IS NOT NULL AND (MIN((groups.parent_id IS NULL)::int))::bool)::int as parent_type
The Postgres query works, but is there a way to avoid the explicit casting there? Postgres 查询有效,但有没有办法避免在那里进行显式转换?
you could declare a version of min that works on booleans.你可以声明一个适用于布尔值的 min 版本。
Create AGGREGATE min( x boolean ) (
stype=boolean,
sfunc=booland_statefunc,
initcond=true
);
or you could just use the bool_and
aggregate.或者你可以只使用
bool_and
聚合。
MAX(groups.id) IS NOT NULL AND bool_and(groups.parent_id IS NULL) as parent_type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.