postgresql “语言'plpgsql'易失性”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12577004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:20:12  来源:igfitidea点击:

what does “LANGUAGE 'plpgsql' VOLATILE” mean?

postgresqlplpgsql

提问by Dorsey

When I create or update a function or procedure in a Postgres database I see LANGUAGE 'plpgsql' VOLATILEat the end of function.
What does this mean and what is its purpose?

当我在 Postgres 数据库中创建或更新函数或过程时,我会LANGUAGE 'plpgsql' VOLATILE在函数末尾看到。
这是什么意思,它的目的是什么?

回答by Akash KC

From Postgres docs:

来自Postgres 文档

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().

VOLATILE 表示即使在单个表扫描中函数值也可以更改,因此无法进行优化。从这个意义上说,相对较少的数据库函数是易变的;一些例子是 random()、currval()、timeofday()。但请注意,任何具有副作用的函数都必须归类为 volatile,即使其结果是可预测的,以防止调用被优化掉;一个例子是 setval()。

回答by Erwin Brandstetter

Not least, LANGUAGE 'plpgsql' VOLATILEmeans that somebody didn't get the memo.

尤其是,LANGUAGE 'plpgsql' VOLATILE意味着有人没有收到备忘录。

The language name in CREATE FUNCTIONis an identifier and should not be quoted. Should be:

中的语言名称CREATE FUNCTION是一个标识符,不应被引用。应该:

LANGUAGE plpgsql VOLATILE

Malpractice can lead to confusing errors. More details in this related answer:
PostgreSQL procedural language "C" not found

不当行为会导致令人困惑的错误。此相关答案中的更多详细信息:
未找到 PostgreSQL 过程语言“C”