duanbai1370
2011-07-21 09:24
浏览 54
已采纳

PHP搜索功能在pgsql表中查找

I want to make a search function in my website. I want to search for a string in all fields of my table (about 13 columns). If one row contains a field that matches the string (like operator) I want it to be added to result.

Example

|field 1 | field 2 | field 3|
 some      string     test    
 test      some      string
 one       simple    string

Now basically if I search for the string "test" I want to have the first two rows.

Is there a wildcard option for WHERE that I could do something :

SELECT * from my.table WHERE * like '%string%';

图片转代码服务由CSDN问答提供 功能建议

我想在我的网站上创建一个搜索功能。 我想在我的表的所有字段中搜索一个字符串(大约13列)。 如果一行包含与字符串匹配的字段(如运算符),我希望将其添加到结果中。

示例

  | field 1 | 场2 | 字段3 | 
一些字符串测试
测试一些字符串
一个简单的字符串
   
 
 

现在基本上如果我搜索字符串“test”我想要 前两行。

我是否可以为WHERE做一个通配符选项:

SELECT * from my.table WHERE * like'%string%';

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsgk0386 2011-07-21 10:02
    已采纳

    There is no such syntax in PostgreSQL (or any other DBMS).

    As Spudley pointed out using a query like like '%string%' will be quite slow.

    If this is something that is needed very often you should definitely look into PostgreSQL's full text search capabilities.

    点赞 评论

相关推荐 更多相似问题