问题
When I create or update a function or procedure in a Postgres database I see LANGUAGE 'plpgsql' VOLATILE at the end of function.
What does this mean and what is its purpose?
回答1:
From Postgres docs:
VOLATILE indicates that the function value can change even within a single table scan, so no optimizations can be made. Relatively few database functions are volatile in this sense; some examples are random(), currval(), timeofday(). But note that any function that has side-effects must be classified volatile, even if its result is quite predictable, to prevent calls from being optimized away; an example is setval().
回答2:
Not least, LANGUAGE 'plpgsql' VOLATILE means that somebody didn't get the memo.
The language name in CREATE FUNCTION is an identifier and should not be quoted. Should be:
LANGUAGE plpgsql VOLATILE
Malpractice can lead to confusing errors. More details in this related answer:
PostgreSQL procedural language "C" not found
来源:https://stackoverflow.com/questions/12577004/what-does-language-plpgsql-volatile-mean