Simple question about running a function.

From: SQL Padawan <sql_padawan(at)protonmail(dot)com>
To: "pgsql-novice(at)lists(dot)postgresql(dot)org" <pgsql-novice(at)lists(dot)postgresql(dot)org>
Subject: Simple question about running a function.
Date: 2021-11-26 16:35:30
Message-ID: auapJ5ZJCo1pvdzR6GK_1Fdqi7utxKRWBiCA-C0DrSZDyW5aBGNhlcvrxe4gGJOEKr6UpB7or2KwaOocBqudGlkX-OqEdriszoj5awt3ptU=@protonmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice


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!

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message SQL Padawan 2021-11-26 17:36:58 Re: Simple question about running a function.
Previous Message SQL Padawan 2021-11-26 15:00:38 Re: Turn dead tuples into temporal data?