PostgreSQL 11 - Procedures

后端 未结 2 1954
一向
一向 2020-12-21 03:58

With the latest update of PostgreSQL supporting procedures. The official blog, quoted that \"As opposed to functions, procedures are not required to return a val

相关标签:
2条回答
  • 2020-12-21 04:06

    You can have INOUT parameters in a procedure.

    You call a procedure with the CALL statement; if there are any INOUT parameters, the statement will return a result row just like SELECT.

    Here is an example that uses a procedure that returns a refcursor:

    CREATE PROCEDURE testproc(INOUT r refcursor) LANGUAGE plpgsql AS
    $$BEGIN
       r := 'cur';
       OPEN r FOR VALUES (1), (42), (12321);
    END;$$;
    
    BEGIN;
    
    CALL testproc(NULL);
    
      r  
    -----
     cur
    (1 row)
    
    FETCH ALL FROM cur;
    
     column1 
    ---------
           1
          42
       12321
    (3 rows)
    
    COMMIT;
    
    0 讨论(0)
  • 2020-12-21 04:11

    How about using the RAISE statement?

    https://www.postgresql.org/docs/10/static/plpgsql-errors-and-messages.html

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