BEGIN;
SELECT set_config('unil.tmp', (select nextval('object_id_seq'))::text, true);

INSERT INTO object SELECT (select current_setting('unil.tmp')::int) AS id,foo.* FROM (SELECT createdon,updatedon,creator FROM object WHERE id=12) AS foo;
INSERT INTO trustee SELECT (select current_setting('unil.tmp')::int) AS id,foo.* FROM (SELECT isgroup FROM trustee WHERE id=12) AS foo;
UPDATE pgroup SET id = (select current_setting('unil.tmp')::int) WHERE id = 12;
UPDATE trustee SET isgroup = false WHERE id = 12;
INSERT INTO person SELECT 12 AS id,'__temp__' AS username, foo.* FROM (SELECT name,password,active,email,language,fts FROM person WHERE id=143) AS foo;
UPDATE object SET creator = 12 WHERE creator = 143;
UPDATE membership SET person = 12 WHERE person = 143;
UPDATE nij_person_data SET person = 12 WHERE person = 143;
UPDATE survey_result SET person = 12 WHERE person = 143;
DELETE FROM person WHERE id = 143;
UPDATE person SET username = 'pmargot' WHERE id = 12;
DELETE FROM trustee WHERE id = 143;
DELETE FROM object WHERE id = 143;
--UPDATE person SET id = 12 WHERE id = 143;

--ROLLBACK;
