C functions with COMMIT/ROLLBACK?

From: Elliot Chance <elliotchance(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: C functions with COMMIT/ROLLBACK?
Date: 2010-12-26 10:35:47
Message-ID: 69A427EC-1419-4372-82AF-CA8F8B005E4A@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi everyone,

Is is possible to add handlers so that a C function is fired when a transaction is committed or rolled back, for example (pseudo code):

BEGIN;
CALL my_function(1);
CALL my_function(2);
CALL my_function(3);
ROLLACK;

my_function()
Create "my_file.txt.tmp"
Write some information to it

commit_handle()
Rename "my_file.txt.tmp" to "my_file.txt"

rollback_handle()
Delete "my_file.txt"

OK, now is it possible to get postgres to call commit_handle() or rollback_handle() for COMMIT and ROLLBACK respectively? Is it even possible to carry context information (for C) throughout an entire transaction?

P.S. Yes, I understand how silly that example is and all the things practically wrong with it but its the concept of firing a C function when a transaction ends and whether it succeeded or not.

Browse pgsql-general by date

  From Date Subject
Next Message zeljko 2010-12-26 11:27:53 Re: Compress data sent to client
Previous Message Elliot Chance 2010-12-26 08:20:33 Re: #include <funcapi.h>