mysql和postgresql转义字符探究
总结
mysql依靠反斜杠\转义, postgresql 依靠单引号转义
mysql 客户端
mysql> create table usr (name varchar(5), age integer); Query OK, 0 rows affected (0.05 sec) mysql> insert into usr values ('kate', 28); Query OK, 1 row affected (0.01 sec) mysql> insert into usr values ('kate\'', 28); Query OK, 1 row affected (0.01 sec) mysql> select * from usr; +-------+------+ | name | age | +-------+------+ | kate | 28 | | kate' | 28 | +-------+------+ 2 rows in set (0.00 sec) mysql> insert into usr values ('kate\\', 28); Query OK, 1 row affected (0.01 sec) mysql> select * from usr; +-------+------+ | name | age | +-------+------+ | kate | 28 | | kate' | 28 | | kate\ | 28 | +-------+------+ 3 rows in set (0.00 sec) mysql> insert into usr values ('kate"', 28); Query OK, 1 row affected (0.01 sec) mysql> select * from usr; +-------+------+ | name | age | +-------+------+ | kate | 28 | | kate' | 28 | | kate\ | 28 | | kate" | 28 | +-------+------+ 4 rows in set (0.00 sec)
postgresql客户端
test=# create table usr (name varchar(5), age integer); CREATE TABLE test=# insert into usr values ('kate', 28); INSERT 0 1 test=# insert into usr values ('kate''', 28), ('kate\', 28), ('kate"', 28); INSERT 0 3 test=# select * from usr; name | age -------+----- kate | 28 kate' | 28 kate\ | 28 kate" | 28