For now I'm trying to finish my 1st approach
(without "on delete cascade") and the following
strangely fails with
ERROR: syntax error at "temp"
DETAIL: Expected record variable, row variable, or list of scalar
variables following INTO.
CONTEXT: compilation of PL/pgSQL function "pref_delete_user" near line 3
create or replace function pref_delete_user(_id varchar,
_reason varchar) returns void as $BODY$
begin
select gid into temp temp_gids from pref_scores where id=_id;
delete from pref_scores where gid in
(select gid from pref_scores where id=_id);
delete from pref_games where gid in
(select gid from pref_scores where id=_id);
delete from pref_rep where author=_id;
delete from pref_rep where id=_id;
delete from pref_catch where id=_id;
delete from pref_game where id=_id;
delete from pref_hand where id=_id;
delete from pref_luck where id=_id;
delete from pref_match where id=_id;
delete from pref_misere where id=_id;
delete from pref_money where id=_id;
delete from pref_pass where id=_id;
delete from pref_status where id=_id;
delete from pref_users where id=_id;
end;
$BODY$ language plpgsql;
Eventhough the same command works ok on the psql-prompt:
# select gid into temp temp_gids from pref_scores where id='OK446163742289';
SELECT
# select * from temp_gids ;
gid
------
1895
1946
1998
2094
2177
2215
(6 rows)