Re: Transactions in rules..

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Fabrizio Mazzoni <fabrizio(at)macron(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Transactions in rules..
Date: 2001-07-09 14:48:37
Message-ID: 200107091448.f69Emb707462@jupiter.us.greatbridge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Fabrizio Mazzoni wrote:
> Can i use transactions in rules??
> I was trying something like:
>
> create rule x_test as
> on insert to view1
> do instead
> (
> begin;
> insert into test1 values (new.a,new.b);
> insert into test2 values (new.c,new.d);
> commit;
> );
>
> But when i give this command in psql i always get an error..

There is no way to execute a statement without having a
transaction in PostgreSQL. If you're not inside of a
transaction block, even a simple SELECT from the client
(psql, application) will have it's own transaction.

For your above case, if you don't do BEGIN/COMMIT, the INSERT
will have it's own Xact with automatic COMMIT (if no ERROR
happens). The rule actions will allways belong to the same
Xact the INSERT does, so either all is committed or nothing.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2001-07-09 15:17:14 [PATCH] Partial indicies again
Previous Message Roman Smirnov 2001-07-09 14:45:02 PostgreSQL for Windows