单引号后,我无法在PostgreSQL中用分号创建字符串。 例如。我需要创建一个像这样的字符串:
Delhi is India's capital; It's a beautiful state
如何创建这样的字符串?
我尝试了以下操作:
select 'Delhi is India\'s capital; It\'s a beautiful state'
我遇到以下错误:
Invalid operation: unterminated quoted string at or near "'Delhi is India\'s capital"
Position: 8;
答案 0 :(得分:2)
在SQL中,不要用反斜杠转义单引号,而是将它们加倍。分号不需要转义。
所以您应该使用
SELECT 'Delhi is India''s capital; It''s a beautiful state';
答案 1 :(得分:1)
尝试Dollar-Quoted String Constants
knayak=# select $$Delhi is India's capital; It's a beautiful state$$ as s;
s
--------------------------------------------------
Delhi is India's capital; It's a beautiful state
(1 row)