如何寻找用于一个特定的东西在表postgres/node.js

0

的问题

目前,我正在使用postgres,访问它通过一个节点服务器。

我卡住的感觉如何,我要搜索一个特定的期限内表,以便作出改变。 我知道我可以选择的某些项目,但是我不知道如何搜索内的项目。

说我的表是:

动物 可爱的 可怕的
媒体的狗 是的 没有
小狗 是的 没有
毛茸茸的狗 是的 没有
大狗 是的 是的
大型猫科动物 没有 是的
小鱼 没有 没有

突然间,我得到一点狗,现在我想改变一切的含的'狗|狗'可怕的:是的。

我真的不能找到任何好处的资源创造的功能。 也许我们忽略的东西。

现在我使用的是简单的选择是这样的:

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)
  })
});
javascript node.js postgresql sql
2021-11-24 02:38:38
1

最好的答案

2

我不知道你obscurification语言(node.js)但Postgres谓你正在寻找可 干净。 或种情况下转换柱 animal. 所以

select animal 
  from petlist 
 where scary = 'no' 
   and animal ilike '%dog'; 

-- or if nodejs complains about ilike then 
select animal 
  from petlist 
 where scary = 'no' 
   and lower(animal) like '%dog'; 

因此,或许是这样的:

app.get('/update/:type', (req, res) => {
  pool.query("SELECT animal FROM petlist WHERE scary = 'no' AND animal ILIKE $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)
  })
});

与req。参数。客户设置的字符串 %的狗.

2021-11-24 23:06:34

这是太棒了! 谢谢你,我不知道干净。. 这是一点点的痛苦得到node.js通过正确的术语与撇号和百分比的标志,但我到了那里最终和它完美的作品。 谢谢你了!
SGPascoe

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................