如何 select 一列在字段中出现两个单引号
How to select a column to appear with two single quote in the field
这是我的 postgresql 查询
select 'insert into employee(ID_NUMBER,NAME,OFFICE) values ('''||ID_NUMBER||''','''||NAME||''','''||replace(DESIGNATION,'&','and')||''','''||replace(DEPT_NAME,'&','and')||''')' as col
from icare_employee_view
where id_number='201403241'
order by name;
产出
insert into employee(ID_NUMBER,NAME,OFFICE) values ('201403241','ABINUMAN, JOSEPHINE CALLO','Assistant AGrS Principal for Curriculum and Instruction','AGrS Principal's Office')
但我需要 'AGrS Principal's Office'
才能成为 'AGrS Principal''s Office'
但我需要 'AGrS Principal's 办公室' 'AGrS Principal''s Office'
非常感谢任何关于如何修复我的 PostgreSQL 查询的建议或解决方案
您好,请查看 pgDocs:
quote_literal ( text ) → text
Returns the given string suitably quoted to be used as a string
literal in an SQL statement string. Embedded single-quotes and
backslashes are properly doubled. Note that quote_literal returns null
on null input; if the argument might be null, quote_nullable is often
more suitable. See also Example 43.1.
quote_literal(E'O'Reilly') → 'O''Reilly'
这是我的 postgresql 查询
select 'insert into employee(ID_NUMBER,NAME,OFFICE) values ('''||ID_NUMBER||''','''||NAME||''','''||replace(DESIGNATION,'&','and')||''','''||replace(DEPT_NAME,'&','and')||''')' as col
from icare_employee_view
where id_number='201403241'
order by name;
产出
insert into employee(ID_NUMBER,NAME,OFFICE) values ('201403241','ABINUMAN, JOSEPHINE CALLO','Assistant AGrS Principal for Curriculum and Instruction','AGrS Principal's Office')
但我需要 'AGrS Principal's Office'
才能成为 'AGrS Principal''s Office'
但我需要 'AGrS Principal's 办公室' 'AGrS Principal''s Office'
非常感谢任何关于如何修复我的 PostgreSQL 查询的建议或解决方案
您好,请查看 pgDocs:
quote_literal ( text ) → text
Returns the given string suitably quoted to be used as a string literal in an SQL statement string. Embedded single-quotes and backslashes are properly doubled. Note that quote_literal returns null on null input; if the argument might be null, quote_nullable is often more suitable. See also Example 43.1.
quote_literal(E'O'Reilly') → 'O''Reilly'