Note that there are some explanatory texts on larger screens.

plurals
  1. POCREATE FUNCTION error "This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA"
    primarykey
    data
    text
    <p>Our database has a function to generate an order number. It reads a value from a Settings table, increments it, then returns the new value. For example:</p> <pre><code>CREATE FUNCTION NextOrderNumber() RETURNS INTEGER UNSIGNED NOT DETERMINISTIC BEGIN DECLARE number INTEGER UNSIGNED; UPDATE Settings SET IntegerValue=LAST_INSERT_ID(IntegerValue+1) WHERE KeyName='NextOrderNumber'; SET number=LAST_INSERT_ID(); return number; END </code></pre> <p>Note: Don't critique this function I know it has flaws it's just for illustration.</p> <p>We use this function as follows:</p> <pre><code>INSERT INTO Orders(OrderNumber, ...) SELECT NextOrderNumber(), ... </code></pre> <p>When binary logging is enabled, CREATE FUNCTION gives this error:</p> <blockquote> <p>This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you <em>might</em> want to use the less safe log_bin_trust_function_creators variable)</p> </blockquote> <p>Regardless of what binlog_format is set, is there really a problem with the above function? According to my reading of the relevant <a href="http://dev.mysql.com/doc/refman/5.1/en/stored-programs-logging.html" rel="noreferrer">MySQL page</a> I can't see any reason why this function would be incompatible with replication, with either ROW or STATEMENT level binary logging.</p> <p>If the function is safe, setting the global log_bin_trust_function_creators=1 makes me uneasy. I don't want to disable this check for all functions, just this one. Could I instead just flag the function as NO SQL to suppress the warning? I tried it and it worked. Will this cause any problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload