I've got another great advice to use DELETE ... USING instead of DELETE ... (SUB-SELECT), so my procedure looks now like this (for archive): create or replace function pref_delete_user(_id varchar, _reason varchar) returns void as $BODY$ begin create temporary table temp_gids (gid int not null) on commit drop; insert into temp_gids (gid) select gid from pref_scores where id=_id; delete from pref_scores p using temp_gids t where p.gid = t.gid; delete from pref_games p using temp_gids t where p.gid = t.gid; /* more delete's here */ end; $BODY$ language plpgsql; -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general