1

How to use update as a inner subquery in postgresql?

update unit_has_jobcard 
    set status = 'approval' 
where id = (update jobcard_has_approvals 
                      set approve = true 
            where id = 27 
            returning id);

I need to update two tables in single query. addBatch helps multiple queries hit a table in single time. But i need to know if is this possible.

1 Answer 1

2

You need a common table expression to update two tables in a single statement:

with approvals as (
  update jobcard_has_approvals 
     set approve = true 
  where id = 27 
  returning id  
)
update unit_has_jobcard
  set status = 'approval' 
where id = (select id from approvals);
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.