Re: Simple question about running a function.

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Simple question about running a function.
Дата
Msg-id CAKFQuwbXhSd_2udmXNamPyt6Rdv-jsKG7cQ6weP=TnoxCZyHqA@mail.gmail.com
обсуждение исходный текст
Ответ на Simple question about running a function.  (SQL Padawan <sql_padawan@protonmail.com>)
Список pgsql-novice
On Fri, Nov 26, 2021 at 9:35 AM SQL Padawan <sql_padawan@protonmail.com> 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.

В списке pgsql-novice по дате отправления:

Предыдущее
От: SQL Padawan
Дата:
Сообщение: Re: Simple question about running a function.
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Simple question about running a function.