Unanswered: Set a variable by select into <variable> max(<expression>)
I get an ERROR: “query string argument of EXECUTE is null”:
"loop_count = 20000;" works well.
"select into loop_count max(index) from players;" returns an error ("select max(index) from players;" returns a number).
Does anyone know the different ?
CREATE OR REPLACE FUNCTION insert_line(target_index integer)
declare loop_count integer;
loop_count = 20000;
-- Using the following assignment instead of the above assignment returns an error
-- select into loop_count max(index) from players;
EXECUTE 'UPDATE players SET index = index + 1 WHERE players.index = ' || loop_count;
loop_count = loop_count - 1;
IF loop_count < $1 + 1 THEN
EXIT; -- exit loop
LANGUAGE 'plpgsql' VOLATILE;