0

So I need a query that would null the content in specific field. That's quite easy, but I need it with a limit that I would specify. For selecting the field with LIMIT and FOR UPDATE SKIP LOCKED I know the query. I need something similar but with UPDATE. Here what I've come with:

UPDATE e_message SET message = null FROM (SELECT * FROM e_message where created < :created ORDER BY :created LIMIT :limit FOR UPDATE SKIP LOCKED)

I specify the created and limit variables in java.

Would this work or did I do something wrong?

1 Answer 1

1

You are almost there:

UPDATE e_message AS e
SET message = null
FROM (SELECT id FROM e_message
      where created < :created
      ORDER BY :created
      LIMIT :limit
      FOR UPDATE SKIP LOCKED) AS e2
WHERE e.id = e2.id;
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.