PostgreSQL 转义特殊字符

PostgreSQL About 853 words

E''

select E'$\abcd', E'abcd\'';

输出

postgres=# select E'$\abcd', E'abcd\'';
 ?column? | ?column?
----------+----------
 $abcd    | abcd'
(1 row)

'

select '''abcd';

输出

postgres=# select '''abcd';
 ?column?
----------
 'abcd
(1 row)

$$

select $$abcd$$, $$'abcd$$, $$\'abcd$$, $$$abcd$$;

输出

postgres=# select $$abcd$$, $$'abcd$$, $$\'abcd$$, $$$abcd$$;
 ?column? | ?column? | ?column? | ?column?
----------+----------+----------+----------
 abcd     | 'abcd    | \'abcd   | $abcd
(1 row)

\

默认没有转义功能,默认standard_conforming_strings = on

show standard_conforming_strings;
SET standard_conforming_strings = on;
SET standard_conforming_strings = off;

当该参数的值为off时就可以直接使用反斜杠作为转义字符里

select '\'abc';

MyBatis

select * from app_version where #{keywords} = ANY(string_to_array(program_language, ','));

参考

https://www.postgresql.org/docs/current/sql-syntax-lexical.html

Views: 642 · Posted: 2023-11-16

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh