小编cod*_*ann的帖子

在 postgresql 中搜索文本时寻找简单的 contains 方法

我是 PostgreSQL 世界的新手,所以我提前道歉,因为不知道这些问题是否有明显的答案。

基本上我在寻找两件事。首先是一个简单的基于“包含”的搜索,其中 python 等效项类似于:

def find_all_containing( input_array=[], target ):
    output=[]
    for i in input_array:
        if target in i:
            output.append(i)
    return(output) 
Run Code Online (Sandbox Code Playgroud)

在我目前正在构建的数据库中,从逻辑上讲,如果我试图显示描述中包含“evil”的所有片段标题,我倾向于相信 SQL 命令看起来有点像这样。

SELECT title FROM snippets WHERE 'evil' in description;
/* or */
SELECT title FROM snippets WHERE description CONTAINS 'evil';
Run Code Online (Sandbox Code Playgroud)

我编写了一个内联 python 函数,它返回一个 'TRUE' 或 'FALSE' 来完成以下工作。

/* contains function here */
CREATE FUNCTION contains (input_text text, target text) RETURNS text AS $$
if target in input_text:
  return("TRUE")
return("FALSE")
$$ LANGUAGE plpythonu;

/* working command of …
Run Code Online (Sandbox Code Playgroud)

postgresql embedded full-text-search python

11
推荐指数
1
解决办法
3万
查看次数

标签 统计

embedded ×1

full-text-search ×1

postgresql ×1

python ×1