Postgres 数据类型整数和布尔值
Postgres data types integer and boolean
我有一个 sql table(9.3 版 PostgreSQL),带有字段(旅游字符变化,旅游时间 int)...我想写一个查询,如 case when tour = 'A' then tourtime = 2 when tour = 'B' then tourtime = 3 else 0
等。 .
但是我得到了错误
CASE types integer and boolean cannot be matched
这是为什么?
在你的案例中你有树枝:
case when tour = 'A'
then tourtime = 2
when tour = 'B'
then tourtime = 3
else 0
end
前两个,你有布尔表达式((tourtime = 2)
和(tourtime = 3)
),根据[=列的值是true
或false
15=]。在第三个中,您有一个整数表达式 (0
).
当系统尝试推断结果的类型时,它匹配三种类型,发现它们不同。
因此,您应该拥有所有整数表达式或布尔表达式,具体取决于您想要的结果。
我有一个 sql table(9.3 版 PostgreSQL),带有字段(旅游字符变化,旅游时间 int)...我想写一个查询,如 case when tour = 'A' then tourtime = 2 when tour = 'B' then tourtime = 3 else 0
等。 .
但是我得到了错误
CASE types integer and boolean cannot be matched
这是为什么?
在你的案例中你有树枝:
case when tour = 'A'
then tourtime = 2
when tour = 'B'
then tourtime = 3
else 0
end
前两个,你有布尔表达式((tourtime = 2)
和(tourtime = 3)
),根据[=列的值是true
或false
15=]。在第三个中,您有一个整数表达式 (0
).
当系统尝试推断结果的类型时,它匹配三种类型,发现它们不同。
因此,您应该拥有所有整数表达式或布尔表达式,具体取决于您想要的结果。