<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="cs">
	<id>http://postgres.cz/index.php?action=history&amp;feed=atom&amp;title=Stored_procedure_proposal</id>
	<title>Stored procedure proposal - Historie editací</title>
	<link rel="self" type="application/atom+xml" href="http://postgres.cz/index.php?action=history&amp;feed=atom&amp;title=Stored_procedure_proposal"/>
	<link rel="alternate" type="text/html" href="http://postgres.cz/index.php?title=Stored_procedure_proposal&amp;action=history"/>
	<updated>2026-05-12T23:42:25Z</updated>
	<subtitle>Historie editací této stránky</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>http://postgres.cz/index.php?title=Stored_procedure_proposal&amp;diff=241&amp;oldid=prev</id>
		<title>85.160.82.252: /* STEP 2 */</title>
		<link rel="alternate" type="text/html" href="http://postgres.cz/index.php?title=Stored_procedure_proposal&amp;diff=241&amp;oldid=prev"/>
		<updated>2007-02-22T20:00:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;STEP 2&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nová stránka&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Proposal: adding new database objects - stored procedures&lt;br /&gt;
-----&lt;br /&gt;
=== STEP 1 ===&lt;br /&gt;
Properties: &lt;br /&gt;
* non atomic&lt;br /&gt;
* allows explicit transaction control (per SQL/PSM)&lt;br /&gt;
* cannot be used from SELECT statement (use statement CALL)&lt;br /&gt;
* allows getting references to INOUT, OUT parameters&lt;br /&gt;
* IN parameters can be expression, but if all arguments are variables we can use FASTCALL&lt;br /&gt;
* allows default values (simplify maintainance procedures)&lt;br /&gt;
* allow using RETURN value statement (returned value is readable via GET DIAGNOSTICS var = RETURN_STATUS (SQL/PSM)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Why: &lt;br /&gt;
* conformance with SQL/PSM&lt;br /&gt;
* simplify porting stored procedures from others databases&lt;br /&gt;
* allows solving some task, which need ref to variables (variable binding, etc)&lt;br /&gt;
* allows choosing right function with specified result type (currently we can specify only IN and INOUT args)&lt;br /&gt;
* allows faster calling stored rutines (FASTCALL)&lt;br /&gt;
* allows using VACUUM in stored procedure&lt;br /&gt;
&lt;br /&gt;
If host environment can put Datum references, then H.E. can call procedures with INOUT and OUT args. If not, &lt;br /&gt;
then it can only call procedures with IN params.&lt;br /&gt;
&lt;br /&gt;
How:&lt;br /&gt;
* own simple executor&lt;br /&gt;
&lt;br /&gt;
=== STEP 2 ===&lt;br /&gt;
Properties:&lt;br /&gt;
* allow unbounded queries&lt;br /&gt;
* allow multirecordset output&lt;br /&gt;
* every recordset is sended immediatly (procedures aren&amp;#039;t atomic, higher interactivity, less memmory usage)&lt;br /&gt;
&lt;br /&gt;
Why:&lt;br /&gt;
* allow writing complex analytic or administration procedures with non regular output&lt;br /&gt;
* simplify porting stored procedures from Sybase based DBMS (Microsoft SQL server, MySQL)&lt;br /&gt;
* allow strategy: everywhere is stored procedure &lt;br /&gt;
&lt;br /&gt;
Case:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BEGIN TRANSACTION&lt;br /&gt;
  -- long time data update operation &lt;br /&gt;
  SELECT * FROM ... -- test output etap 1&lt;br /&gt;
  -- long time data update operation &lt;br /&gt;
  SELECT * FROM ... -- test output etap 2&lt;br /&gt;
  IF NOT force THEN&lt;br /&gt;
    ROLLBACK&lt;br /&gt;
  ELSE&lt;br /&gt;
    COMMIT&lt;br /&gt;
  ENDIF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Previous proposals:&lt;br /&gt;
* http://archives.postgresql.org/pgsql-hackers/2004-09/msg00412.php Neil Conway (only syntactic changest for plpgsql, drop PERFORM statement)&lt;br /&gt;
* http://archives.postgresql.org/pgsql-hackers/2004-09/msg00702.php Gavin Sherry&lt;br /&gt;
* http://archives.postgresql.org/pgsql-hackers/2005-02/msg00783.php Tom Lane reply on previous proposal (result is OUT params for functions)&lt;br /&gt;
* http://archives.postgresql.org/pgsql-hackers/2005-11/msg01015.php Martijn van Oosterhout  (Returning multiple result sets)&lt;br /&gt;
&lt;br /&gt;
What we currently cannot:&lt;br /&gt;
* transaction control&lt;br /&gt;
* bind variables&lt;br /&gt;
&lt;br /&gt;
What we can, ugly (more code, less readable, ugly solution)&lt;br /&gt;
* choose function with selected returned type (with specific function name)&lt;br /&gt;
* multirecord set (setof refcursor .. not intuitive, missing support in psql)&lt;br /&gt;
* default values&lt;br /&gt;
&lt;br /&gt;
What impact of missing feature: bigger preferences for MySQL 5.x (current support of stored procedures is basic, it isn&amp;#039;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.&lt;/div&gt;</summary>
		<author><name>85.160.82.252</name></author>
	</entry>
</feed>