PostgreSQL where 子句条件检查包含单引号的值

PostgreSQL where clause condition check with value that contains single quote

假设我在 Postgres 数据库中有一个 employees table,我必须在其中为员工姓名插入一个值,即 john's

因为它是 Postgres,我将通过将它们加倍来转义单引号 ' -> ''

所以john's会变成john''s

现在,当我 select 使用 select 查询 那个特定的 row/instance 时,我必须再次加倍引用。所以对于 select 值 john''s 我必须写 'john''''s' 并且我的查询变成 -

select * from employees where name = 'john''''s'

这是最好的方法吗?要么 对于这些特定类型的数据(包含引号),是否可以替代此数据插入过程和 selection?有什么建议吗?

不,您不必将转义引号加倍:

select * 
from employees 
where name = 'john''s'