如何解决 postgresql sql 查询中的此语法错误以更新单个列中的多行
How to resolve this syntax error in a postgresql sql query to update multiple rows in a single column
鉴于 Postgres 数据库中的 tableA
,我需要更新字段中的多行 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';
但我收到以下语法错误:
Error: syntax error at or near ","
您可以使用一个 CASE
语句来完成:
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;
试试看 here.
鉴于 Postgres 数据库中的 tableA
,我需要更新字段中的多行 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';
但我收到以下语法错误:
Error: syntax error at or near ","
您可以使用一个 CASE
语句来完成:
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;
试试看 here.