pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Glen Huang <heyhgl@gmail.com>
To: Brian Dunavant <dunavant@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Is replacing transactions with CTE a good idea?
Date: Thu, 1 Apr 2021 23:06:32 +0800
Message-ID: <79097C11-B045-4D98-A427-4A82477E2634@gmail.com> (raw)
In-Reply-To: <CAJ2+uGUYptunbADng2ywqq_pKuKSFS8aTpoLiLJz-9-qhWqcSw@mail.gmail.com>
References: <CAJ2+uGUYptunbADng2ywqq_pKuKSFS8aTpoLiLJz-9-qhWqcSw@mail.gmail.com>

> When you deal with updates/deletes, things can be trickier

Care to expand why they are tricker? I presume they run the risk of being referenced more than once?

> On Apr 1, 2021, at 10:58 PM, Brian Dunavant <dunavant@gmail.com> wrote:
> 
> 
>> 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
>  

view thread (22+ messages)  latest in thread

Message-ID: <79097C11-B045-4D98-A427-4A82477E2634@gmail.com>
Permalink:  ../79097C11-B045-4D98-A427-4A82477E2634@gmail.com/
Also on:    postgresql.org/message-id/79097C11-B045-4D98-A427-4A82477E2634@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: heyhgl@gmail.com, dunavant@gmail.com
  Subject: Re: Is replacing transactions with CTE a good idea?
  In-Reply-To: <79097C11-B045-4D98-A427-4A82477E2634@gmail.com>
  References: <CAJ2+uGUYptunbADng2ywqq_pKuKSFS8aTpoLiLJz-9-qhWqcSw@mail.gmail.com> <79097C11-B045-4D98-A427-4A82477E2634@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox