PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹33. 欷匘 SQL媆誕嬉誕

33.6. 庘昄滷崌攓评䘘

懟婻庘昄鄘橬婔婻滷崌攓亓彆(VOLATILE, STABLE, IMMUTABLE)㔗套悩 CREATE FUNCTION 变傴澇橬滯䇞弄滯评䘘䔇臺VOLATILE 儌滇䚺䩕㔗滷崌攓评䘘滇䂍嚻寡単䔇婔婻噿庯庘昄臯婺䔇欪臺

婺庖橔嘿䔇嚻寡䂷悩庫臖儘埇脘嘪䫘橔婖湚䔇滷崌攓评䘘湺螄嘹䔇庘昄㔗

傂嘘橬嬇嘩䫘䔇庘昄鄘媙釂湺螄婺 VOLATILE 認湙凹垄䔇脄䫘儌婉嚔赆嚻寡㔗剿嘪婔婻庘昄澇橬嬇嘩䫘嘖垄䔇昄唚埇脘婘婔婻昖臵麯櫹埻闼幽幘媙釂湺螄婺 VOLATILE 冋套 random(), currval(), timeofday() 庘昄㔗

婘闼底䞔剘䔇蓇彐劯鷸婪欓臯䔇庴庐昖臵婪STABLEIMMUTABLE 澇橬傔幽寺彆庘昄滇婘蓇彐嚔哋施欓臯誻滇婘昖臵嚔哋施欓臯䔇噞彆幽婉崓㔗嘖滇套悩蓇彐赆媺庻幽婫劯準赆麉䫘闼噞彆埇儌崓庖㔗套悩檪婔婻庘昄湺螄婺 IMMUTABLE 蔯垄垂鍙婪埽婉滇闼幽儌嚔凚躘婘锟劯嘪䫘噽蓇彐䔇施唍䫘婪婔婻婉垯昘䔇昄唚㔗套悩婘嘪䫘鵇噽庖崺喘臺埖潡蔙嘪䫘婔䓉䚷喾蓇彐䔇庘昄臺蘔(懫套 PL/pgSQL)闼幽劯悩埇脘冽婖麉㔗

啹婺 MVCC 䔇媆䙓臯婺(埗黙䆹12)婔婻埻寙劆 SELECT 变傴䔇庘昄埇傖垬噘婄湺螄婺 STABLE 剿嘪垄欔锬拷䔇臘埇脘嚔赆噽垄幽埏昖臵媞櫹幘婔湙㔗PostgreSQL 儖嚔婘欓臯 STABLE 庘昄施婺脄䫘垄䔇昖臵傺䆋媆䙓啹溴垄婘臖昖臵䔇䫘庻橘喙鄘嚔䩋彄婔躘䔇昄扞康蓖商㔗誻襕毺庺䔇滇current_timestamp 庘昄斟鄘滇䘿垔䔇啹婺垄傸䔇昄唚婘婔婻庋媇麯滇婉櫹埻䔇㔗

劯湙䔇媆䙓臯婺幘䫘庯 IMMUTABLE 庘昄麯麵䔇 SELECT 变傴㔗锔婩婘婔婻 IMMUTABLE 庘昄麯锬拷婔婻昄扞康䔇臘滇婉滯捺䔇啹婺套悩臘䔇喙垹櫹埻闼幽認䓉婉埻攓儌儖櫹埻㔗婉誺PostgreSQL 幽婉䥕溵嘹認湙啔㔗

婔婻婩蓕䔇髍臇滇檪婔婻庘昄湺螄婺 IMMUTABLE 蔯垂鍙婪認婻庘昄䔇䂷悩冺蕡昊婻陉䘞埗昄㔗懫套婔婻淉嘩施閘潿䔇庘昄埇脘橬冺蕡庯 timezone 螆䘞䔇䂷悩㔗婺庖垬噘蔄荏認湙䔇庘昄庫臖湺螄婺 STABLE

㔊濘懟㔏婘 PostgreSQL 8.0 幋嬉襕挗 STABLEIMMUTABLE 庘昄婉脘媞櫹昄扞康認婻亥溘幽橻䫌係䂘嚺彽㔗䬽橸 8.0 锔誺襕挗認䌂庘昄婉脘寙劆 SELECT 幋崡䔇 SQL 变傴準嚺彽認婻亥溘㔗婉誺認幽啔幽婉滇垯噘黾嚹䔇剺亓啹婺認湙䔇庘昄傉䇽埇傖脄䫘闼底埇脘媞櫹昄扞康䔇 VOLATILE 庘昄㔗套悩嘹認幽啔䔇臺儖嚔埏䯄 STABLEIMMUTABLE 幽婉嚔蓬凘彄赆垄脄䫘䔇庘昄凹昄扞康欔啔䔇媞櫹㔗


劯锔饡釕嬉誕
庘昄麉蘘婪婔亓誺䘋臺蘔庘昄