Ted
Ted

Reputation: 1760

Replace values in select

I have simple select:

select id, user_value
from some_table

Where user_value is some number. When user_value will be 0, I need to replace it to 1.

Upvotes: 0

Views: 26

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269953

Just use a case expression:

select id,
       (case when user_value = 0 then 1 else user_value end) as user_value
from some_table;

If you want to actually change the value in the table, then just use update with filtering:

update some_table
    set user_value = 1
    where user_value = 0;

Upvotes: 1

Related Questions