'How to resolve this syntax error in a postgresql sql query to update multiple rows in a single column
Given the tableA in a Postgres database, I need to update multiple rows in the field column_a:
UPDATE tableA
SET
column_a = CASE WHEN column_a = 'conserve' THEN column_a = 'fixed',
column_a = CASE WHEN column_a = 'balance' THEN column_a = 'moderate',
column_a = CASE WHEN column_a = 'balance growth' THEN column_a = 'moderate growth',
column_a = CASE WHEN column_a = 'aggressive' THEN column_a = 'moderate/agressive';
but I'm getting the following syntax error:
Error: syntax error at or near ","
Solution 1:[1]
You can do it with one single CASE statement:
UPDATE tableA
SET
column_a = CASE WHEN column_a = 'conserve' THEN 'fixed'
WHEN column_a = 'balance' THEN 'moderate'
WHEN column_a = 'balance growth' THEN 'moderate growth'
WHEN column_a = 'aggressive' THEN 'moderate/agressive'
END;
Try it here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
