Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lSs9t-0005kV-Ld for pgsql-general@arkaria.postgresql.org; Sun, 04 Apr 2021 02:06:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lSs9s-0000jC-Ep for pgsql-general@arkaria.postgresql.org; Sun, 04 Apr 2021 02:06:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lSs9s-0000j4-4W for pgsql-general@lists.postgresql.org; Sun, 04 Apr 2021 02:06:36 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lSs9p-0005Sb-Vc for pgsql-general@lists.postgresql.org; Sun, 04 Apr 2021 02:06:35 +0000 Received: by mail-oo1-xc30.google.com with SMTP id j10-20020a4ad18a0000b02901b677a0ba98so2141781oor.1 for ; Sat, 03 Apr 2021 19:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=NA8KN4mCVdj7XLW/+wQGSAvajNOe1zE1JFL2AQ4BRjc=; b=SrEIr2OQQlyqM4VQrzULqGn6RRfDH/tEM/876uO28Hr428E5XoBv0r0PIs1jpWYvcM 0w0CRkoL43bi3wcmjFrfXIzFfRsTqK0DROLSlYUgMKYc9ZF7yeuwc94tJEFGsFt5H4cA HxeBt9otpiyi/ZBKzxjmAZOHPPPQvhbN3HEm1o6XVmCbj/VhBzIUIU8ttFvuaXcgTpAm usrprOMNeV3Qlfo1Das/xrW1OTjgMMjZzwdGHdPOQn11zQmN0S07DmugTraIf2+idzZa vqRE3x7U3Sy8MeIsc8oO+7oC0w5yeO2OwxEM+00YAvrgtVFW7guHnRXkObwM4PUcobbW WR7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=NA8KN4mCVdj7XLW/+wQGSAvajNOe1zE1JFL2AQ4BRjc=; b=Vgryuyz6HXrjPLw6axm3LJNopMiI0tUgypyaMOx+ay4agICzbq8Nfu6ZoVdMuEHsb2 9Ms4P+RSr++Y8veX5Xtife1pEg2XGRM4vANFhT3mUb9fly8HTH/U7ZJVSIryGMrjn9W/ oYn6yJKwsePVnCys85/G/5Y25TO2wCza/nPl/Xzu07oANLgnBOR0gwLu1zEqehDBJLaV RNlpomiJ67d49nUWQGsgjHAqX889hMAu8L1gLLYs8C2f6Hc9xY2TG50UQvvh/fnJixNK mgCqFFEtibfEyJFyodaTDxCBjLJszclOMISP+rpH0+7nsztQhbqUyp+dUxeQfi7+15d4 RLXw== X-Gm-Message-State: AOAM530mfsQIVHzf1UZ5XMHkpC22DJXT3wo6+MjhquxgHW0ZVpMx+Ytc dVtRARmO3sUwjvk3l1/EaZxtywMw8w8= X-Google-Smtp-Source: ABdhPJxt46IWNUDBnNdB3NXmroEf78Cu5dJE2RufyPba5RHMVszjdj9FE2RtORdMyDQCi/3lSdyYKA== X-Received: by 2002:a4a:d24c:: with SMTP id e12mr17545935oos.73.1617501992839; Sat, 03 Apr 2021 19:06:32 -0700 (PDT) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id c26sm2976537otm.51.2021.04.03.19.06.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Apr 2021 19:06:32 -0700 (PDT) Subject: Re: Is replacing transactions with CTE a good idea? To: pgsql-general@lists.postgresql.org References: <02654280-7b22-1231-8de7-c74a1a62e426@gmail.com> From: Ron Message-ID: Date: Sat, 3 Apr 2021 21:06:31 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <02654280-7b22-1231-8de7-c74a1a62e426@gmail.com> Content-Type: multipart/alternative; boundary="------------AAAAF2A58BA6C490C4571D9C" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------AAAAF2A58BA6C490C4571D9C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 > > 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. --------------AAAAF2A58BA6C490C4571D9C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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@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
 
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.
--------------AAAAF2A58BA6C490C4571D9C--