Stored procedure proposal

Z PostgreSQL
Skočit na navigaci Skočit na vyhledávání

Proposal: adding new database objects - stored procedures



  • non atomic
  • allows explicit transaction control (per SQL/PSM)
  • cannot be used from SELECT statement (use statement CALL)
  • allows getting references to INOUT, OUT parameters
  • IN parameters can be expression, but if all arguments are variables we can use FASTCALL
  • allows default values (simplify maintainance procedures)
  • allow using RETURN value statement (returned value is readable via GET DIAGNOSTICS var = RETURN_STATUS (SQL/PSM)


  • conformance with SQL/PSM
  • simplify porting stored procedures from others databases
  • allows solving some task, which need ref to variables (variable binding, etc)
  • allows choosing right function with specified result type (currently we can specify only IN and INOUT args)
  • allows faster calling stored rutines (FASTCALL)
  • allows using VACUUM in stored procedure

If host environment can put Datum references, then H.E. can call procedures with INOUT and OUT args. If not, then it can only call procedures with IN params.


  • own simple executor



  • allow unbounded queries
  • allow multirecordset output
  • every recordset is sended immediatly (procedures aren't atomic, higher interactivity, less memmory usage)


  • allow writing complex analytic or administration procedures with non regular output
  • simplify porting stored procedures from Sybase based DBMS (Microsoft SQL server, MySQL)
  • allow strategy: everywhere is stored procedure


  -- long time data update operation 
  SELECT * FROM ... -- test output etap 1
  -- long time data update operation 
  SELECT * FROM ... -- test output etap 2
  IF NOT force THEN

Previous proposals:

What we currently cannot:

  • transaction control
  • bind variables

What we can, ugly (more code, less readable, ugly solution)

  • choose function with selected returned type (with specific function name)
  • multirecord set (setof refcursor .. not intuitive, missing support in psql)
  • default values

What impact of missing feature: bigger preferences for MySQL 5.x (current support of stored procedures is basic, it isn't top topic for mysql and mysql users too, but 3 months work and they had similar sql/psm implementation like plpgpsm with better SQL/PSM support and with all missing features. Currently they have more then one comparable data engines.