Re: Simple question about running a function. - Mailing list pgsql-novice

From SQL Padawan
Subject Re: Simple question about running a function.
Date
Msg-id I_azqsn6cR13UFT5V7_Q8SYvAMXs71wWZ_GvVQnTEEuNk2ilyPNKUbJsbKAaLXLindkisjBr2-7Ed1kfKsIubulp-HQCNXnRiltQiTS9rXk=@protonmail.com
Whole thread Raw
In response to Simple question about running a function.  (SQL Padawan <sql_padawan@protonmail.com>)
Responses Re: Simple question about running a function.
List 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!




pgsql-novice by date:

Previous
From: SQL Padawan
Date:
Subject: Simple question about running a function.
Next
From: "David G. Johnston"
Date:
Subject: Re: Simple question about running a function.