无法在 postgres 插入中插入问号
Cannot insert question mark in postgres insert
我正在尝试 运行 一个简单的 Postgres SQL 插入:
insert into "Resources" values(1, 'How are you?');
但是插入后的结果是:
ID Data
--- ------
1 How are you
我知道,要插入像单引号这样的字符,我必须用另一个单引号将其转义,例如:我做不到。
但是怎么办呢?
Knex 将 ?
和 ??
解释为位置绑定。您通常会在 knex.raw()
语句中使用它们来安全地注入某种变量。例如:
knex.raw('UPDATE my_table SET my_column = ?', [someVariable])
像这样的绑定参数对于原始语句通常是必需的,以确保您注入的任何内容都被安全转义。
这就是为什么您会看到这种行为。好消息是,您可以避开问号。来自 Knex.js documentation:
To prevent replacement of ? one can use the escape sequence \?.
我正在尝试 运行 一个简单的 Postgres SQL 插入:
insert into "Resources" values(1, 'How are you?');
但是插入后的结果是:
ID Data
--- ------
1 How are you
我知道,要插入像单引号这样的字符,我必须用另一个单引号将其转义,例如:我做不到。
但是怎么办呢?
Knex 将 ?
和 ??
解释为位置绑定。您通常会在 knex.raw()
语句中使用它们来安全地注入某种变量。例如:
knex.raw('UPDATE my_table SET my_column = ?', [someVariable])
像这样的绑定参数对于原始语句通常是必需的,以确保您注入的任何内容都被安全转义。
这就是为什么您会看到这种行为。好消息是,您可以避开问号。来自 Knex.js documentation:
To prevent replacement of ? one can use the escape sequence \?.