[英]Why does query_to_xml return an error for a volatile query in Postgres?
I'd like to understand why something like this doesn't work in PostgreSQL:我想了解为什么这样的事情在 PostgreSQL 中不起作用:
SELECT query_to_xml('CREATE TABLE my_table (my_column INTEGER)', FALSE, TRUE, '')
It gives ERROR: CREATE TABLE is not allowed in a non-volatile function
.它给出ERROR: CREATE TABLE is not allowed in a non-volatile function
。 Fair enough - but when I checked the signature for query_to_xml
, it is marked as volatile:很公平 - 但当我检查query_to_xml
的签名时,它被标记为易变的:
CREATE OR REPLACE FUNCTION pg_catalog.query_to_xml(
query text,
nulls boolean,
tableforest boolean,
targetns text)
RETURNS xml
LANGUAGE 'internal'
COST 100
VOLATILE STRICT PARALLEL UNSAFE
AS [...]
Follow-up question: If this isn't allowed, is there any other way to run a dynamic volatile query without PL/PgSQL?后续问题:如果不允许这样做,有没有其他方法可以在没有 PL/PgSQL 的情况下运行动态易失性查询?
The following functions map the contents of relational tables to XML values.以下函数将 map 关系表的内容转换为 XML 的值。
That means you can't use this function for a CREATE TABLE statement, just SELECT data from a table and turn that into an XML.这意味着您不能将此 function 用于 CREATE TABLE 语句,只能将表中的 SELECT 数据转换为 XML。
The error message however, could be better, I agree.然而,错误信息可能会更好,我同意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.