Amit Khandekar - 2013-07-22

Basically we should handle subtransactions correctly to support savepoints.

Another area which uses subtransactions is the exception block in PL languages. pl/pgsql uses subtransactions to implement exception blocks. That's probably why these no not work currently:

CREATE or replace FUNCTION merge_db(key INT, data TEXT) RETURNS VOID AS
$$
BEGIN

-- first try to insert the key
-- if we get a unique-key failure, update the record with new data
BEGIN
INSERT INTO db(a,b) VALUES (key, data);
EXCEPTION WHEN unique_violation THEN
UPDATE db SET b = data WHERE a = key;
END;
END;
$$
LANGUAGE plpgsql;

SELECT merge_db(1, 'david');
SELECT merge_db(1, 'john');

The above should insert 'david', and then update the same record with 'john'. This is not working in XC.