title: Firebird constant UDF
body: <p>Is it possible to make an EXTERNAL FUNCTION as constant or immutable, so that Firebird knows not to recompute it during the course of one SQL statement?</p>
  
  <p>In the example below (Firebird 2.1), I'd like GETTIMEOFDAY() to behave like CURRENT_TIMESTAMP, but it is instead evaluated twice:</p>
  
  <pre><code>SQL&gt; DECLARE EXTERNAL FUNCTION gettimeofday -- gettimeofday(2) wrapper
  CON&gt;         RETURNS DOUBLE PRECISION BY VALUE
  CON&gt;         ENTRY_POINT 'UDF_gettimeofday' MODULE_NAME 'udf_gettimeofday';
  
  SQL&gt; SELECT CURRENT_TIMESTAMP AS ts,
  CON&gt;        CAST(GETTIMEOFDAY() AS INTEGER) AS time_t,
  CON&gt;        FB_SLEEP(2) AS zzz
  CON&gt;   FROM rdb$database
  CON&gt;  CROSS JOIN (SELECT 1 AS foo
  CON&gt;                FROM rdb$database
  CON&gt;               UNION ALL
  CON&gt;              SELECT 2
  CON&gt;                FROM rdb$database) d;
  
                         TS       TIME_T          ZZZ
  ========================= ============ ============
  2011-03-15 20:57:46.0390    1300244268            0
  2011-03-15 20:57:46.0390    1300244270            0
  </code></pre>
  
  <p>As you can see, the value of "TS" remains constant, but my "TIME_T" advances across the FB_SLEEP() calls.  (FB_SLEEP is a convenience function to pause for the given number of seconds.)</p>
  
  <p>Is what I want possible?  I know PostgreSQL permits precisely this with its concept of <a href="http://www.postgresql.org/docs/current/static/xfunc-volatility.html" rel="nofollow">STABLE</a> FUNCTIONS.</p>