小编use*_*735的帖子

基于参数构建 where 子句

在 PostgreSQL 中,我试图在一个函数中构建一个 where 子句,该函数使用入站参数来确定 IN 的内容

例如:

select fld1, count(fld1)
from xyz
where fld1 in (
    case $1
        when 1 then 'Value1'
        when 2 then 'Value2'
        when 3 then '''Value1'',''Value2'''
        when 4 then '''Value4'',''Value5'',''Value6'''
    else NULL
)
group by fld1
Run Code Online (Sandbox Code Playgroud)

值 1 和值 2 一样正常工作,值 3 和 4 在语法上没有失败,但没有返回任何行。

postgresql case where

3
推荐指数
1
解决办法
1538
查看次数

标签 统计

case ×1

postgresql ×1

where ×1