我有一张桌子test(id,name).
我需要插入样值: user's log,'my user',customer's.
insert into test values (1,'user's log');
insert into test values (2,''my users'');
insert into test values (3,'customer's');
Run Code Online (Sandbox Code Playgroud)
如果我运行上述任何语句,我会收到错误.
如果有任何方法可以正确地做到这一点请分享.我不想要任何准备好的陈述.
是否可以使用sql转义机制?
我使用pg node-postgres 包为我的项目进行了以下设置:
简单的表 'tmp' 如下所示:
根据jsonORG和postgres 文档对象:
{"foo" : true}
Run Code Online (Sandbox Code Playgroud)
是语法上有效的 JSON,当使用 pgAdmin 查询工具时:
UPDATE tmp SET data = '{"foo": false}' WHERE id = '1'
Run Code Online (Sandbox Code Playgroud)
工作正常,但是当我尝试使用 pg 通过快速路由更新我的表时:
router.put('/updateTMP', (req, res) => {
// I use dummies in this case instead of req.body.someKey for testing purposes
let dummyJSON = {"foo":true};
let dummyID = 1;
pg.query(`UPDATE tmp SET data = '${dummyJSON}' WHERE id = '${dummyID}'`, (errUpdate, responseUpdate) => {
if (!errUpdate) { // NO ERROR …Run Code Online (Sandbox Code Playgroud)