Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hVyar-0004OS-Uu for pgsql-general@arkaria.postgresql.org; Wed, 29 May 2019 13:26:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hVyaq-000319-IU for pgsql-general@arkaria.postgresql.org; Wed, 29 May 2019 13:26:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hVyaq-000312-5n for pgsql-general@lists.postgresql.org; Wed, 29 May 2019 13:26:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hVyan-0000Mx-T7 for pgsql-general@postgresql.org; Wed, 29 May 2019 13:26:10 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x4TDQ5fa030291; Wed, 29 May 2019 09:26:05 -0400 From: Tom Lane To: PegoraroF10 cc: pgsql-general@postgresql.org Subject: Re: with and trigger In-reply-to: <1559130758966-0.post@n3.nabble.com> References: <1559130758966-0.post@n3.nabble.com> Comments: In-reply-to PegoraroF10 message dated "Wed, 29 May 2019 04:52:38 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2486.1559136365.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 29 May 2019 09:26:05 -0400 Message-ID: <2487.1559136365@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PegoraroF10 writes: > We like to use With to insert, update and return some value to user. But= some > informations of those related tables are not available on that time, is = that > a bug ? No, see the "WITH Clause" section of the SELECT reference page: The primary query and the WITH queries are all (notionally) executed at the same time. This implies that the effects of a data-modifying statement in WITH cannot be seen from other parts of the query, other than by reading its RETURNING output. If two such data-modifying statements attempt to modify the same row, the results are unspecified. This doesn't explicitly talk about triggers, but I think our attitude about the case you're discussing is that the results are unspecified. If a trigger fired in one WITH arm tries to look at the table(s) modified by other WITH arms, it might or might not see those changes. regards, tom lane