Postgres calling a void function

10,284

HINT: If you want to discard the results of a SELECT, use PERFORM instead.

PERFORM  do_something(m.id) 
FROM    MyTable m
WHERE   m.IsActive;

PERFORM is the PL/PgSQL alternative for SELECT for when you want to throw the results away. It cannot be used outside PL/PgSQL. For more information, see the manual.

Share:
10,284
ozczecho
Author by

ozczecho

Currently working at a startup, and occassionally take a few snaps. ozczecho @ Flickr ozczecho @ Redbubble

Updated on June 08, 2022

Comments

  • ozczecho
    ozczecho almost 2 years

    I have a void plsql function:

    CREATE OR REPLACE FUNCTION do_something(p_id BIGINT) 
    RETURNS void
    AS $$
    BEGIN
       insert ....
    END;
    $$ LANGUAGE plpgsql SECURITY DEFINER;
    

    I want to call this function from another plsql function, but inside a query like:

    SELECT  do_something(m.id) 
    FROM    MyTable m
    WHERE   m.IsActive;
    

    When I run the sproc i get:

    ERROR: query has no destination for result data HINT: If you want to discard the results of a SELECT, use PERFORM instead.

    Is it possible to call a void function as part of a select statement?

  • pozs
    pozs about 10 years
    Maybe worth mentioning, PERFORM is only valid in pl/pgsql context.
  • Craig Ringer
    Craig Ringer about 10 years
    Yeah, fair. I usually write much more in depth answers, but this is such a "Did you actually read the error message / search for the error" one...
  • ozczecho
    ozczecho about 10 years
    :-) I Did read the error and I did try "PERFORM"...but I must have fluffed it up...because before it didnt work...and now it does...grrr ...and sorry for wasting everyones time.