What is even more puzzling is that this function works no problem:
create or replace function test_fn_3()
returns VOID as $$
DECLARE
BEGIN
FOR r IN 1..10000 LOOP
INSERT INTO tab VALUES (100);
END LOOP;
END;
$$ LANGUAGE plpgsql;
but this one fails:
create or replace function test_fn_4()
returns VOID as $$
DECLARE
BEGIN
FOR r IN 1..10000 LOOP
SELECT ('A string');
END LOOP;
END;
$$ LANGUAGE plpgsql;
It's something to do with output - SELECT obviously returns something, whereas INSERT doesn't - but that's not strictly
true.It returns success or failure?
SELECT test_fn_5() fails:
create or replace function test_fn_5()
returns VOID as $$
DECLARE
BEGIN
FOR r IN 1..10000 LOOP
INSERT INTO tab VALUES (100) RETURNING *;
END LOOP;
END;
$$ LANGUAGE plpgsql;
because of the RETURNING *!
So, it's something to do with output/returned data?
How do I tell psql/PL/pgSQL that I want to suppress the output for
the test?
Trying to run
DO $$ BEGIN SELECT 'blah'; END; $$;
from the command line also fails with the
ERROR: query has no destination for result data
I'd really like to understand what's going on?
SQLP!
> SQLP!