public inbox for [email protected]  
help / color / mirror / Atom feed
From: SQL Padawan <[email protected]>
To: SQL Padawan <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Simple question about running a function.
Date: Fri, 26 Nov 2021 17:36:58 +0000
Message-ID: <I_azqsn6cR13UFT5V7_Q8SYvAMXs71wWZ_GvVQnTEEuNk2ilyPNKUbJsbKAaLXLindkisjBr2-7Ed1kfKsIubulp-HQCNXnRiltQiTS9rXk=@protonmail.com> (raw)
In-Reply-To: <auapJ5ZJCo1pvdzR6GK_1Fdqi7utxKRWBiCA-C0DrSZDyW5aBGNhlcvrxe4gGJOEKr6UpB7or2KwaOocBqudGlkX-OqEdriszoj5awt3ptU=@protonmail.com>
References: <auapJ5ZJCo1pvdzR6GK_1Fdqi7utxKRWBiCA-C0DrSZDyW5aBGNhlcvrxe4gGJOEKr6UpB7or2KwaOocBqudGlkX-OqEdriszoj5awt3ptU=@protonmail.com>


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!






view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Simple question about running a function.
  In-Reply-To: <I_azqsn6cR13UFT5V7_Q8SYvAMXs71wWZ_GvVQnTEEuNk2ilyPNKUbJsbKAaLXLindkisjBr2-7Ed1kfKsIubulp-HQCNXnRiltQiTS9rXk=@protonmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox