1

I want to use postgres sql to update the latest row in the DB.

Here is how I get the latest row:

SELECT id, state_json, update_timestamp FROM ui_rules ORDER BY update_timestamp DESC LIMIT 1

How can I update and override that single row?

UPDATE ui_rules SET state_json = '{..}' WHERE ?;

1 Answer 1

2

Assuming id is unique, you can add a where condition or join:

UPDATE ui_rules
    SET state_json = '{..}'
    WHERE id = (SELECT id
                FROM ui_rules
                ORDER BY update_timestamp DESC
                LIMIT 1
               );
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.