Re: with and trigger

2019-05-29 Thread Tom Lane
Ron writes: > On 5/29/19 8:26 AM, Tom Lane wrote: >> 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

Re: with and trigger

2019-05-29 Thread Andreas Kretschmer
> >Are CTEs still optimization fences? >https://www.2ndquadrant.com/en/blog/postgresql-ctes-are-optimization-fences/ Yes, but not in 12. Regards, Andreas -- 2ndQuadrant - The PostgreSQL Support Company

Re: with and trigger

2019-05-29 Thread Ron
On 5/29/19 8:26 AM, Tom Lane wrote: 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 p

Re: with and trigger

2019-05-29 Thread Tom Lane
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

Re: with and trigger

2019-05-29 Thread PegoraroF10
Well, I think is not a transaction problem, because if you do the same thing on a DO it will work. DO $$ declare vMaster_ID integer; begin insert into Master(Customer_ID, Field2) values(1, 'BlaBla') returning Master_ID into vMaster_ID; insert into Detail(Master_ID, Product_ID, ProductValue)

Re: with and trigger

2019-05-29 Thread Fabrízio de Royes Mello
Em qua, 29 de mai de 2019 às 08:52, PegoraroF10 escreveu: > > 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 ? > > with > Master(Master_ID) as (insert into Master(Customer_ID, Fi

Re: with and trigger

2019-05-29 Thread Geoff Winkless
On Wed, 29 May 2019 at 12:52, PegoraroF10 wrote: > This trigger will not work because Master record was not inserted yet. > That seems reasonable. Since the transaction is meant to be atomic any select within the query should return data from tables as they are at the start of the transaction, t

with and trigger

2019-05-29 Thread PegoraroF10
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 ? with Master(Master_ID) as (insert into Master(Customer_ID, Field2) values(1, 'BlaBla') returning Master_ID), Detail as (insert int