How to search a key word in all columns of big query table?

孤者浪人 提交于 2019-12-08 03:58:16

问题


I'm using the big query to see the data in my google cloud. I want to search a keyword in all columns of a particular table.

Ex: I'm searching for Dubai. I need the result of entries where ever the Dubai word present in any column.


回答1:


Below is for BigQuery Standard SQL and assumes column names do not contain search word (can be adjusted to address this too)

#standardSQL
SELECT *
FROM `yourproject.yourdataset.yourtable` t
WHERE REGEXP_CONTAINS(LOWER(TO_JSON_STRING(t)), r'dubai')

You can test / play with above using dummy data as below

#standardSQL
WITH `yourproject.yourdataset.yourtable` AS (
  SELECT 1 id, 'Los Angeles' col1, 'New York' col2 UNION ALL
  SELECT 2, 'Dubai', 'San Francisco' UNION ALL
  SELECT 3, 'atlanta', 'dubai' UNION ALL
  SELECT 4, 'I love Dubai', 'Me too'
)
SELECT *
FROM `yourproject.yourdataset.yourtable` t
WHERE REGEXP_CONTAINS(LOWER(TO_JSON_STRING(t)), r'dubai')

Hope above can be good starting point for you to apply to your specific case

But note: cost is scan of whole table - so check cost before running against read (hopefully big) data :o)



来源:https://stackoverflow.com/questions/48414383/how-to-search-a-key-word-in-all-columns-of-big-query-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!