gpt4 book ai didi

PostgreSQL : using a statement as case condition

转载 作者:行者123 更新时间:2023-11-29 11:47:45 24 4
gpt4 key购买 nike

当我使用语句作为case 条件时,它总是返回false

select * from table order by (case when (true) then id else 1/0 end)  desc -- works 
select * from table order by (case when (select true) then id else 1/0 end) desc -- exception
select * from table order by (case when (1=1) then id else 1/0 end) desc -- works
select * from table order by (case when (select 1=1) then id else 1/0 end) desc -- exception

这种情况有什么问题?

最佳答案

CASE WHEN 期望根据 documentation 的条件得到一个 boolean 结果:

Each condition is an expression that returns a boolean result.

SELECT 语句返回一个关系(是的,单行有单列,boolean 类型和值 TRUE 但这仍然不是一个 boolean)。

关于PostgreSQL : using a statement as case condition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29874606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com