Find value in any column in a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2023 07:21 PM
Hi,
I'm not sure if this is a possible scenario, but is there, by any chance a way to query all the columns of a table for searching a value?
Explanation: I want to search for a specific value in all the columns of a databricks table. I don't know which column that value might be present, or not. I just am not sure what column holds that value.
Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2025 11:11 AM
I also have this same requirement now and cant find the solution for this yet. Any help would be good. thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2025 02:53 PM
Select * from table as t where '1234' in (t.*)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2025 10:37 AM
You can do something like this, but first run the following code in Python:
table = "my_table"
value = "foo"
cols = spark.table(table).columns
sql = f"""
SELECT *
FROM {table}
WHERE
{" OR ".join([f"CAST({c} AS STRING) LIKE '%{value}%'" for c in cols])}
"""
print(sql)
, then run this sql query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2025 12:48 PM
My blog: https://databrickster.medium.com/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2025 02:03 PM - edited 12-03-2025 02:05 PM
Thanks Hubert, using this wild card seems really helpful