Do I use CTEs or Transactions to combine queries? postgresql

Viewed 1517

Documentation says:

Transactions: The essential point of a transaction is that it bundles multiple steps into a single, all-or-nothing operation. The intermediate states between the steps are not visible to other concurrent transactions, and if some failure occurs that prevents the transaction from completing, then none of the steps affect the database at all.

Data-modifying CTEs: This allows you to perform several different operations in the same query... The sub-statements in WITH are executed concurrently with each other and with the main query. Therefore, when using data-modifying statements in WITH, the order in which the specified updates actually happen is unpredictable

My needs:

  • All-or-nothing operation;
  • Not nested queries;
  • RETURNING;
  • Understanding the difference & where to use each one.

Example: look at design bellow. What should I use here, when I CRUD data? How my request should look like?

DB design

0 Answers
Related