Re: Is replacing transactions with CTE a good idea?

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Is replacing transactions with CTE a good idea?
Date: 2021-04-04 02:06:31
Message-ID: b6567fde-6617-2144-177e-857ce980dc4a@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4/1/21 10:04 AM, Rob Sargent wrote:
> On 4/1/21 8:58 AM, Brian Dunavant wrote:
>> On Thu, Apr 1, 2021 at 10:49 AM Glen Huang <heyhgl(at)gmail(dot)com
>> <mailto:heyhgl(at)gmail(dot)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
> This must assume auto-commit mode where every single statement is "committed"?

That's the only way to explain an otherwise very puzzling question. OP must
not do lots of DML in each transaction.

--
Angular momentum makes the world go 'round.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2021-04-04 02:10:08 Re: Slick way to update multiple tables.
Previous Message Adrian Klaver 2021-04-03 20:17:14 Re: Upgrading from 11 to 13