3

While fiddling with the performance impact of calling a procedure from another procedure vs. repeating the code in Postgres 13, I found that you can invoke other procedures by using either CALL or PERFORM.

I googled for differences but the only similar thing I found was

Which addresses PERFORM vs. EXECUTE and not PERFORM vs. CALL.

Does anyone know what the difference is? Which one should I use (when calling a procedure from a PL/pgSQL procedure)?

Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137
Awer Muller
  • 497
  • 5
  • 15
  • 1
    You can not use `perform` to call a stored procedure. The only way to call a procedure is to use `call` https://dbfiddle.uk/?rdbms=postgres_13&fiddle=f9682a6888fb157e2522f80294669996 – a_horse_with_no_name May 26 '21 at 17:23
  • You're right, my bad. I realized I'm using a void function, not a procedure. Thanks! – Awer Muller May 26 '21 at 17:30

1 Answers1

6

CALL is an SQL command to execute a PROCEDURE and was added with Postgres 11, when SQL procedures were added. You cannot call a procedure with SELECT.

PERFORM is a PL/pgSQL command to execute any SELECT statement and discard the result by replacing the SELECT keyword (incl. plain FUNCTION calls). It has been part of PL/pgSQL since forever.

You cannot CALL a function, and you cannot PERFORM a procedure.
You can use PERFORM anywhere you could SELECT (without INTO) inside a PL/pgSQL code block.

db<>fiddle here

Related:

Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137