Thank you, I have rewritten it into:
RegardsBEGIN
PERFORM check_positions(in_uid, in_gid, in_tiles);
CREATE TEMP TABLE _words(word varchar, score integer) ON COMMIT DROP;
INSERT INTO _words
SELECT
out_word AS word,
max(out_score) AS score
FROM check_words(in_uid, in_gid, in_tiles)
GROUP BY word, gid;
PERFORM check_positions(in_uid, in_gid, in_tiles);
CREATE TEMP TABLE _words(word varchar, score integer) ON COMMIT DROP;
INSERT INTO _words
SELECT
out_word AS word,
max(out_score) AS score
FROM check_words(in_uid, in_gid, in_tiles)
GROUP BY word, gid;