In PostgreSQL, VOLATILE is one of three volatility classifications (VOLATILE, STABLE, IMMUTABLE) that can be assigned to a user-defined function or procedure. A VOLATILE function can read or modify database state, depend on session settings, call random() or clock_timestamp(), or otherwise produce different output for the same input. Because its result is unpredictable, PostgreSQL executes the function every time it appears in a query, forbids constant folding, and prevents its use in index expressions or materialized view definitions.VOLATILE is the default when no classification is given, but explicitly declaring it communicates intent and helps future maintainers. Misclassifying a function can hurt performance or, worse, return stale or incorrect results. Functions that only read data without side effects should be STABLE, while completely deterministic functions should be IMMUTABLE.
STABLE, IMMUTABLE, CREATE FUNCTION, ALTER FUNCTION, DETERMINISTIC, NONDETERMINISTIC, FUNCTION SIDE EFFECTS, VOLATILE TABLE (Teradata)
PostgreSQL 7.3
Yes. If you omit any volatility clause, PostgreSQL marks the function VOLATILE automatically.
No. PostgreSQL blocks VOLATILE functions from index expressions or materialized views because their output can change between scans.
Yes. A VOLATILE function is executed for every row where it appears, skipping constant folding and some plan optimizations. Use STABLE or IMMUTABLE when safe.
Run ALTER FUNCTION function_name(arg_types) VOLATILE; PostgreSQL updates the catalog immediately, and future queries honor the new classification.