【发布时间】:2022-01-02 11:48:11
【问题描述】:
我目前正在使用 postgres,通过节点服务器访问它。
我对如何在表格中搜索特定术语以进行更改感到困惑。我知道我可以选择某些项目,但我不知道如何在项目中进行搜索。
说我的桌子是:
| animal | cuddly | scary |
|---|---|---|
| Medium Dog | yes | no |
| Small Dog | yes | no |
| Fluffy Dog | yes | no |
| Big Dog | yes | yes |
| Big Cat | no | yes |
| Small Fish | no | no |
突然,我被狗咬了,现在我想把所有包含“狗|狗”的东西都改成可怕的:是的。
我真的找不到任何好的资源来创建这个函数。也许我忽略了一些东西。
现在我正在使用这样的简单 SELECT:
app.get('/update/:type', (req, res) => {
pool.query("SELECT animal FROM petlist WHERE scary = 'no' AND animal = $1",[req.params.client],
(error, results) => {
if (error) {
console.log("I selected dog, but I can't see the specific types of dog!")
throw error
}
console.log(results.rows);
res.status(200).json(results.rows)
})
});
【问题讨论】:
-
感谢亨利的编辑,很抱歉把它放在一个 sn-p 盒子里!
标签: javascript sql node.js postgresql