user124123
user124123

Reputation: 1683

Multiple rule replace within single column postgresql

I am trying to select a column and do a multiple replacement i.e

Col1
a
b
c
d

select col1 and replace a = 1, b=2 and c=3

Col1
1
2
3
d

I am aware of update and replace but only for a single rule at a time

Upvotes: 0

Views: 35

Answers (1)

Gurwinder Singh
Gurwinder Singh

Reputation: 39507

You can use CASE:

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

Upvotes: 1

Related Questions