Good afternoon all,
I want to test a function. I have \timing on.
There are two ways of doing this - either use lots of data or run it many times.
I'm using psql.
I wish to run my function many times. So, a small dummy function is here:
create or replace function test_fn()
returns VOID as $$
DECLARE
BEGIN
FOR r IN 1..10000 LOOP
SELECT ('a string');
END LOOP;
END;
$$ LANGUAGE plpgsql;
Compiles no problems - CREATE FUNCTION is returned as expected.
So, I try:
SELECT test_fn();
but receive the error:
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT: PL/pgSQL function test_fn() line 6 at SQL statement
So, I searched and found
DO $$ BEGIN
PERFORM test_fn();
END $$;
but when I run this, I receive the same error - i.e. use PERFORM instead.
I tried
PERFORM test_fn();
and receive the error:
ERROR: syntax error at or near "PERFORM"
LINE 1: PERFORM test_fn();
So, could somebody please tell me how to run a function like this?
Any pointers to references/URLs and especially the documentation would be great - I did search but couldn't find
anything.
A general overview of the "philosophy" underlying this would be helpful - I'm just not "getting" it?
rgs,
SQLP!