CREATE FUNCTION 后面的代码是一个字符串意味着什么?
What does the code following CREATE FUNCTION being a string imply?
来自:
in PostgreSQL, CREATE FUNCTION
is indeed a "SQL statement" but is is merely a
"wrapper" to specify a block of code that is executed by something
different than the SQL query "engine". Postgres (unlike other DBMS)
supports multiple "runtime engines" that can execute the block of code
that was passed to the "CREATE FUNCTION" statement - one artifact of
that is that the code is actually a string so CREATE FUNCTION only
sees a string, nothing else.
"the code is actually a string so CREATE FUNCTION only sees a string, nothing else"的后果是什么?
这是否被视为动态 SQL?与动态 SQL 相比,它是否可以防止或引入 SQL 注入风险?
这与 "the code is not a string" 的其他 RDBMS(如果有的话)有何不同?
谢谢。
所有 3GL+ 代码基本上都是一个字符串。传递给 CREATE FUNCTION
的 "parameter" 是代码(将在核心 SQL 引擎之外执行),它是一个字符串(即 not SQL).
其他 RDMS 仅支持 SQL 作为 function/procedure 正文。
PostgreSQL 具有高度可扩展性,例如,您可以定义自己的过程语言来编写函数。
PostgreSQL 除了必须调用特定的 语言处理程序 来执行函数外,对语言一无所知。
选择实现此方法的方法是简化将代码作为字符串传递。
这只是一个实现细节,不会使 PostgreSQL 函数比其他 RDBMS 更容易或更不容易受到 SQL 注入的攻击。
您必须在几个级别上保护自己免受注入:
函数参数:此处应尽可能选择非字符串数据类型。
函数内的SQL语句:此处应尽可能避免动态SQL,如果必须使用动态SQL,则应插入使用 format
函数的 %L
模式的变量。
同样,无论函数体是否指定为字符串,这都是一样的。
来自
in PostgreSQL,
CREATE FUNCTION
is indeed a "SQL statement" but is is merely a "wrapper" to specify a block of code that is executed by something different than the SQL query "engine". Postgres (unlike other DBMS) supports multiple "runtime engines" that can execute the block of code that was passed to the "CREATE FUNCTION" statement - one artifact of that is that the code is actually a string so CREATE FUNCTION only sees a string, nothing else.
"the code is actually a string so CREATE FUNCTION only sees a string, nothing else"的后果是什么?
这是否被视为动态 SQL?与动态 SQL 相比,它是否可以防止或引入 SQL 注入风险?
这与 "the code is not a string" 的其他 RDBMS(如果有的话)有何不同?
谢谢。
所有 3GL+ 代码基本上都是一个字符串。传递给 CREATE FUNCTION
的 "parameter" 是代码(将在核心 SQL 引擎之外执行),它是一个字符串(即 not SQL).
其他 RDMS 仅支持 SQL 作为 function/procedure 正文。
PostgreSQL 具有高度可扩展性,例如,您可以定义自己的过程语言来编写函数。
PostgreSQL 除了必须调用特定的 语言处理程序 来执行函数外,对语言一无所知。
选择实现此方法的方法是简化将代码作为字符串传递。
这只是一个实现细节,不会使 PostgreSQL 函数比其他 RDBMS 更容易或更不容易受到 SQL 注入的攻击。
您必须在几个级别上保护自己免受注入:
函数参数:此处应尽可能选择非字符串数据类型。
函数内的SQL语句:此处应尽可能避免动态SQL,如果必须使用动态SQL,则应插入使用
format
函数的%L
模式的变量。
同样,无论函数体是否指定为字符串,这都是一样的。