From: | SQL Padawan <sql_padawan(at)protonmail(dot)com> |
---|---|
To: | SQL Padawan <sql_padawan(at)protonmail(dot)com> |
Cc: | "pgsql-novice(at)lists(dot)postgresql(dot)org" <pgsql-novice(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Simple question about running a function. |
Date: | 2021-11-26 17:36:58 |
Message-ID: | I_azqsn6cR13UFT5V7_Q8SYvAMXs71wWZ_GvVQnTEEuNk2ilyPNKUbJsbKAaLXLindkisjBr2-7Ed1kfKsIubulp-HQCNXnRiltQiTS9rXk=@protonmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
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!
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2021-11-26 17:39:51 | Re: Simple question about running a function. |
Previous Message | SQL Padawan | 2021-11-26 16:35:30 | Simple question about running a function. |