0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

BigQueryでまとめて曖昧検索をする

Posted at

BigQueryを使っている際に、「ある項目に、"ABC"または"CDE"という文字列を含む」という絞り込みを行いたい際に、次のようにORでくくっていかないといけないのは、件数が増えていくと非常に書くのが面倒になります。

WHERE 
{Content} like '%ABC%' OR {Content} like '%CDE%' 

WHERE句をANDでくくらないといけないのは、

そこで、次のようにARRAYと正規表現の検索を用いることで、曖昧検索+複数条件が可能になります。

WITH t_search AS(

# Like検索したい単語一覧
SELECT ["ABC","CDE"] as word_list

)

SELECT
*
 FROM `{PROJECT}.{DATASET}.{TABLE}`
WHERE IF(REGEXP_EXTRACT({Content}, (SELECT ARRAY_TO_STRING(word_list,"|") FROM t_search)) is not null, True, False)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?