Re: Are rules transaction safe? - Mailing list pgsql-general

From Doug McNaught
Subject Re: Are rules transaction safe?
Date
Msg-id 87d5idcla5.fsf@asmodeus.mcnaught.org
Whole thread Raw
In response to Re: Are rules transaction safe?  (Oliver Fürst <ofuerst@tsak.net>)
List pgsql-general
Oliver Fürst <ofuerst@tsak.net> writes:

> But is nowhere stated if (multiple) commands inside a rule are treated
> as an implicit transaction as a whole.

If you don't specifically open a transaction at the top level (i.e. in
'psql' or SQL from your application's code), PG will encapsulate every
query you execute within its own transaction.  The statements in any
rules called will execute in the context of that transaction, along
with any other operations such as trigger calls, table updates,
whatever.  If something in that implicit transaction fails, it will be
rolled back; otherwise, it will be committed once the statement is
finished.

Also, you need to think of rules as 'query rewrites' rather than
'code that executes', because that's what they are.

I hope that helps.

-Doug

pgsql-general by date:

Previous
From: Oliver Fürst
Date:
Subject: Re: Are rules transaction safe?
Next
From: "Roderick A. Anderson"
Date:
Subject: SQL Lint