英文:
ERROR: invalid input syntax for type boolean: "DRAFT"
问题
正在进行类似以下的 case 语句
CASE coe_status
WHEN 'PUBLISHED' THEN '已发布'
WHEN 'DRAFT' AND 'REVIEW' THEN '开放'
ELSE '无 COEs'
我遇到的问题是
ERROR: invalid input syntax for type boolean: "DRAFT"
难道没有一种方法可以将它们组合在一起,而不是像这样分开吗
CASE coe_status
WHEN 'PUBLISHED' THEN '已发布'
WHEN 'DRAFT' THEN '开放'
WHEN 'REVIEW' THEN '开放'
ELSE '无 COEs'
<details>
<summary>英文:</summary>
I am doing a case statement like this
CASE coe_status
WHEN 'PUBLISHED' THEN 'Published'
WHEN 'DRAFT' AND 'REVIEW' THEN 'Open'
ELSE 'No-Coes'
The issue I am encountering is that
ERROR: invalid input syntax for type boolean: "DRAFT"
Is there not a way to combine these two so they can have one sum instead of having it like this
CASE coe_status
WHEN 'PUBLISHED' THEN 'Published'
WHEN 'DRAFT' THEN 'Open'
WHEN 'REVIEW' THEN 'Open'
ELSE 'No-Coes'
</details>
# 答案1
**得分**: 1
你正在使用简单形式的`CASE`表达式,其中每个`WHEN`子句只能使用一个条件。相反,你可以使用通用/搜索形式的`CASE`表达式,如下所示:
```sql
CASE
WHEN coe_status = 'PUBLISHED' THEN 'Published'
WHEN coe_status = 'DRAFT' OR coe_status = 'REVIEW' THEN 'Open' -- 或者简单地使用 WHEN coe_status IN ('DRAFT', 'REVIEW') THEN 'Open'
ELSE 'No-Coes'
END
英文:
You are using the simple form of the case expression, by which you can not use more than one condition for each WHEN
clause.
Instead, you could use the general/ searched form of the case expression as the following:
CASE
WHEN coe_status = 'PUBLISHED' THEN 'Published'
WHEN coe_status ='DRAFT' OR coe_status ='REVIEW' THEN 'Open' -- Or simply use, WHEN coe_status IN ('DRAFT', 'REVIEW') THEN 'Open'
ELSE 'No-Coes'
END
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论