【发布时间】:2016-06-12 20:05:37
【问题描述】:
我未能将专为 MySQL 设计的 SQL 查询转换为 Postgres 语法。这是查询:
select if(sendonly = true, 'REJECT', 'OK') AS access from accounts where username = '%u' and domain = '%d' and enabled = true LIMIT 1;
Postgres 没有这个不错的小函数“if()”。我对某些 CASE 子句的第一次尝试失败了。需要修改哪些内容才能在 Postgres 中运行此查询?
【问题讨论】:
-
你做过研究吗?谷歌搜索“postgres if else”会显示 postgresql.org/docs/9.1/static/plpgsql-control-structures.html,这表明存在
IF-THEN-ELSE结构。 -
@ceejayoz 你可能想再仔细看看这个页面,这是关于服务器端 PL/pgSQL 语言的,而不是 SQL 查询。
标签: mysql sql postgresql if-statement select