Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单列postgresql中的多规则替换_Postgresql - Fatal编程技术网

单列postgresql中的多规则替换

单列postgresql中的多规则替换,postgresql,Postgresql,我正在尝试选择一列并进行多次替换,即 Col1 a b c d 选择col1并替换a=1、b=2和c=3 Col1 1 2 3 d 我知道更新和替换,但一次仅针对单个规则您可以使用以下用例: select case when col1 = 'a' then '1' when col1 = 'b' then '2' when col1 = 'c' then '3' else col1 end from table;

我正在尝试选择一列并进行多次替换,即

Col1
a
b
c
d
选择col1并替换a=1、b=2和c=3

Col1
1
2
3
d
我知道更新和替换,但一次仅针对单个规则

您可以使用以下用例:

select
    case when col1 = 'a' then '1'
         when col1 = 'b' then '2'
         when col1 = 'c' then '3'
         else col1
    end
from table;