public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[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 10:39:51 -0700
Message-ID: <CAKFQuwbXhSd_2udmXNamPyt6Rdv-jsKG7cQ6weP=TnoxCZyHqA@mail.gmail.com> (raw)
In-Reply-To: <auapJ5ZJCo1pvdzR6GK_1Fdqi7utxKRWBiCA-C0DrSZDyW5aBGNhlcvrxe4gGJOEKr6UpB7or2KwaOocBqudGlkX-OqEdriszoj5awt3ptU=@protonmail.com>
References: <auapJ5ZJCo1pvdzR6GK_1Fdqi7utxKRWBiCA-C0DrSZDyW5aBGNhlcvrxe4gGJOEKr6UpB7or2KwaOocBqudGlkX-OqEdriszoj5awt3ptU=@protonmail.com>

On Fri, Nov 26, 2021 at 9:35 AM SQL Padawan <[email protected]>
wrote:

> 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.
>

By default there isn't much compiling going on here.  The pl/pgsql code is
just a string that gets executed during query execution.


> 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
>

It's complaining that "SELECT ('a string')" doesn't have a destination.
The fact that you got it to work when you removed that select and replaced
it with an insert proves that.  The CONTEXT line also tells you this in no
uncertain terms.

David J.


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], [email protected]
  Subject: Re: Simple question about running a function.
  In-Reply-To: <CAKFQuwbXhSd_2udmXNamPyt6Rdv-jsKG7cQ6weP=TnoxCZyHqA@mail.gmail.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