我正在处理应用程序,我需要在列中存储 { [ " : ] }
这些字符。
我该怎么做?
答案 0 :(得分:4)
这些角色都不需要特别注意:
create table t (col text);
insert into t
values ('{ [ " : ] }');
但是,如果您打算在该列中存储(有效)JSON 值,最好将其声明为 jsonb
而不是文本:
create table t (col jsonb);
insert into t
values ('{"key1": 42, "key2": [1,2,3]}');
在 SQL 中的字符串文字中唯一需要特别注意的字符是单引号——它被 doubling it 转义,例如:'Arthur''s house'