Re: Is replacing transactions with CTE a good idea? - Mailing list pgsql-general

From Brian Dunavant
Subject Re: Is replacing transactions with CTE a good idea?
Date
Msg-id CAJ2+uGUYptunbADng2ywqq_pKuKSFS8aTpoLiLJz-9-qhWqcSw@mail.gmail.com
Whole thread Raw
In response to Is replacing transactions with CTE a good idea?  (Glen Huang <heyhgl@gmail.com>)
Responses Re: Is replacing transactions with CTE a good idea?  (Rob Sargent <robjsargent@gmail.com>)
Re: Is replacing transactions with CTE a good idea?  (Glen Huang <heyhgl@gmail.com>)
List pgsql-general
On Thu, Apr 1, 2021 at 10:49 AM Glen Huang <heyhgl@gmail.com> wrote:
If I decide to replace all my transaction code with CTE, will I shoot myself in the foot down the road?

I do this all the time and makes code way cleaner.   It's very straightforward with inserts queries.  When you deal with updates/deletes, things can be trickier.  I usually leave these in a transaction if there is any concern.

They can also be hard for future programmers that may not understand SQL.  Make sure you comment your queries for maintainability long term.  

I have yet to regret replacing a transaction with a CTE over the past decade.  YMMV
 

pgsql-general by date:

Previous
From: Glen Huang
Date:
Subject: Is replacing transactions with CTE a good idea?
Next
From: Dave Cramer
Date:
Subject: Re: Is replacing transactions with CTE a good idea?