postgresql INSERT INTO with IF语句
在postgresql INSERT INTO with IF语句,postgresql,Postgresql,在postgresql中,如何在列中插入值。b来自列。a来自同一个表,其中 IF column.a = 1 then column.b = foo, IF column.a = 2 then column.b = bar, IF column.a = 3 then column.b = good, IF column.a = 4 then column.b = bad INSERT不会在列中插入值。它会在表中插入新行。相反,您需要使用。您还需要一些。INSERT不会在列中插入值。它会在表中插
postgresql
中,如何在列中插入值。b
来自列。a来自同一个表,其中
IF column.a = 1 then column.b = foo,
IF column.a = 2 then column.b = bar,
IF column.a = 3 then column.b = good,
IF column.a = 4 then column.b = bad
INSERT不会在列中插入值。它会在表中插入新行。相反,您需要使用。您还需要一些。INSERT不会在列中插入值。它会在表中插入新行。相反,您需要使用。您还需要一些。如果行已经存在,则不需要插入。您需要这样的更新
:
UPDATE your_table
SET b = CASE
WHEN a = 1 then 'foo'
WHEN a = 2 then 'bar'
WHEN a = 3 then 'good'
ELSE 'bad'
END
WHERE some_condition = 'true';
如果行已经存在,则不需要插入。您需要这样的更新
:
UPDATE your_table
SET b = CASE
WHEN a = 1 then 'foo'
WHEN a = 2 then 'bar'
WHEN a = 3 then 'good'
ELSE 'bad'
END
WHERE some_condition = 'true';