0

I am trying to swap multiple column values that were incorrectly swapped due to backend code. I am trying to use the following:

UPDATE insured
SET address1=(:risk_address1_var:=address1), address1 = risk_address1, risk_address1 = :risk_address1_var;

It's not working like it works for mysql as temp variable(using @). I want to execute this sql query in the liquibase migration code.

1
  • 1
    That hack is not needed in Postgres - it properly supports just swapping them in place. The variable is essentially a workaround for a MySQL bug. Commented Aug 27, 2020 at 8:38

1 Answer 1

1

No need for a temporary variable. Unlike MySQL, Postgres allows doing what you want with simply:

UPDATE insured
SET address1 = risk_address1, risk_address1 = address1;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.