0

I have a query that seems to work:

UPDATE questions SET active=TRUE WHERE id=ANY ([1, 5, 7]);

But I also want to set all other rows to active=FALSE

Essentially, I want to do the equivalent of running these two lines

UPDATE questions SET active=FALSE;
UPDATE questions SET active=TRUE WHERE id=ANY ([1, 5, 7]);

But I would like to accomplish this in a single query if possible. Is there a way to do this?

1 Answer 1

2

Use the condition as a Boolean value to set:

UPDATE questions SET active = (id = ANY(array[1, 5, 7]));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.