ERROR: 布尔类型的输入语法无效:"DRAFT"

huangapple go评论65阅读模式
英文:

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 = &#39;PUBLISHED&#39; THEN &#39;Published&#39;
  WHEN coe_status =&#39;DRAFT&#39; OR coe_status =&#39;REVIEW&#39; THEN &#39;Open&#39; -- Or simply use, WHEN coe_status IN (&#39;DRAFT&#39;, &#39;REVIEW&#39;) THEN &#39;Open&#39;
  ELSE &#39;No-Coes&#39;
END

huangapple
  • 本文由 发表于 2023年5月7日 13:52:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定