public inbox for [email protected]  
help / color / mirror / Atom feed
From: SQL Padawan <[email protected]>
To: [email protected] <[email protected]>
Subject: Simple question about running a function.
Date: Fri, 26 Nov 2021 16:35:30 +0000
Message-ID: <auapJ5ZJCo1pvdzR6GK_1Fdqi7utxKRWBiCA-C0DrSZDyW5aBGNhlcvrxe4gGJOEKr6UpB7or2KwaOocBqudGlkX-OqEdriszoj5awt3ptU=@protonmail.com> (raw)


Good afternoon all,

I want to test a function. I have \timing on.

There are two ways of doing this - either use lots of data or run it many times.

I'm using psql.

I wish to run my function many times. So, a small dummy function is here:

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.

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

So, I searched and found

DO $$ BEGIN
    PERFORM test_fn();
END $$;

but when I run this, I receive the same error - i.e. use PERFORM instead.

I tried

PERFORM test_fn();

and receive the error:

ERROR:  syntax error at or near "PERFORM"
LINE 1: PERFORM test_fn();



So, could somebody please tell me how to run a function like this?

Any pointers to references/URLs and especially the documentation would be great - I did search but couldn't find anything.

A general overview of the "philosophy" underlying this would be helpful - I'm just not "getting" it?

rgs,

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: <auapJ5ZJCo1pvdzR6GK_1Fdqi7utxKRWBiCA-C0DrSZDyW5aBGNhlcvrxe4gGJOEKr6UpB7or2KwaOocBqudGlkX-OqEdriszoj5awt3ptU=@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