C functions with COMMIT/ROLLBACK? - Mailing list pgsql-general

From Elliot Chance
Subject C functions with COMMIT/ROLLBACK?
Date
Msg-id 69A427EC-1419-4372-82AF-CA8F8B005E4A@gmail.com
Whole thread Raw
List 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
firinga C function when a transaction ends and whether it succeeded or not. 

pgsql-general by date:

Previous
From: Elliot Chance
Date:
Subject: Re: #include
Next
From: zeljko
Date:
Subject: Re: Compress data sent to client