Why doesn't PostgreSQL give a warning when calling a volatile function
from a stable function?
For example:
CREATE TABLE x (
val double);
CREATE FUNCTION g() RETURNS boolean AS $$
INSERT INTO x SELECT rand() RETURNING val>0.5;
$$ LANGUAGE SQL VOLATILE;
CREATE FUNCTION f() RETURNS boolean AS $$
SELECT g(); -- this is where the stability-violation happens
$$ LANGUAGE SQL STABLE; -- this is a lie
According to the documentation, f() should be marked VOLATILE also, since
calling f() produces side effects. PostgreSQL does not give a warning (or
better yet, an error), this leads me to believe there must be some reason
why this "obvious" mistake is allowed to exist.
No comments:
Post a Comment