XC need to support SAVEPOINT. It is not only for general application but also to support many GUI applications such as Access and Openoffice/Libreoffice. They use SAVEPOINT to implement "undo".
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;
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.