Hi David and thank you for trying to help the terminally stupid!
> > How do I tell psql/PL/pgSQL that I want to suppress the output for
> > the test?
> By doing exactly what the error message told you. Use PERFORM instead of SELECT...on the exact query whose output
youwish to ignore, not an indirect caller.
OK - so, following your input, I searched further and I found a post by Pavel Stehule - great I thought, a major
contributor- see here:
https://stackoverflow.com/a/42922661/470530
his example is this function which I duly created (and not, as you pointed out, compiled!)
CREATE OR REPLACE FUNCTION foo()
RETURNS void AS $$
BEGIN
RAISE NOTICE 'Hello from void function';
END;
$$ LANGUAGE plpgsql;
which I run as a direct call as in the example.
test=# SELECT foo();
NOTICE: Hello from void function
foo
-----
(1 row)
So, then I ran this.
-- in PLpgSQL
DO $$
BEGIN
PERFORM foo(); -- is ok
END;
$$;
with a result I found surprising - as follows.
NOTICE: Hello from void function
DO
Time: 8.704 ms
I thought that the PERFORM "swallowed" the output?
So, then I went back to my own function:
create or replace function test_fn_6()
returns VOID as $$
DECLARE
BEGIN
FOR r IN 1..10000 LOOP
SELECT ('A string');
END LOOP;
END;
$$ LANGUAGE plpgsql;
and then I tried.
DO $$
BEGIN
PERFORM test_fn_6();
END;
$$;
but get 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_6() line 6 at SQL statement
SQL statement "SELECT test_fn_6()"
PL/pgSQL function inline_code_block line 3 at PERFORM
Now, I thought from Pavel Stehule's post that my function's output would/should be swallowed - but then the foo()
exampleproduced a text output?
I'm really puzzled here... I mean what I'm asking for is really simple - pl/pgsql 101 and I can't even get a simple
functionto execute multiple times in the background.
I'm not asking for the sun, moon and stars here...
rgs,
SQLP!
> David J.