How to create function that returns nothing

前端 未结 2 1403
忘掉有多难
忘掉有多难 2021-02-01 00:15

I want to write a function with pl/pgsql. I\'m using PostgresEnterprise Manager v3 and using shell to make a function, but in the shell I must define retu

相关标签:
2条回答
  • 2021-02-01 00:36

    Use RETURNS void like below:

    CREATE FUNCTION stamp_user(id int, comment text) RETURNS void AS $$
        #variable_conflict use_variable
        DECLARE
            curtime timestamp := now();
        BEGIN
            UPDATE users SET last_modified = curtime, comment = comment
              WHERE users.id = id;
        END;
    $$ LANGUAGE plpgsql;
    
    0 讨论(0)
  • 2021-02-01 00:36

    Functions must always return something, although you can use procedures like

    do $$
    

    and start with normal function like

    declare
    ...
    

    but if you still want to do a function just add void after returns.

    0 讨论(0)
提交回复
热议问题