Fri 17 Jun 2011
I’ve been messing with this for a few hours until I finally found this nugget on MySQL:
A view definition is “frozen” by certain statements:
If a statement prepared by PREPARE refers to a view, the view definition seen each time the statement is executed later will be the definition of the view at the time it was prepared. This is true even if the view definition is changed after the statement is prepared and before it is executed. Example:
CREATE VIEW v AS SELECT RAND();
PREPARE s FROM ‘SELECT * FROM v’;
ALTER VIEW v AS SELECT NOW();
EXECUTE s;
The result returned by the EXECUTE statement is a random number, not the current date and time.
Why on earth would anyone do that? Allow me to elaborate…
(more…)