Search for simple object that contains a certain key

Hi all,

I have a simple object column that has cells that look like:

{"path": ['a','b','c'], "target_key": "some_value"}

Is there a way to return all rows from the db that have the key "target_key", regardless of the value?

I know I can look for a particular value with:
app_tables.table.search(column={"target_key": "some_value"}, but was hoping to return rows where the target key exists.

Al

I could go:

rows=[r for r in app_tables.table.search() if 'target_key' in r['simple_object_column']]

but I’m not sure if this is the best way.

Yes, I think that’s the best way to do it with the layout you have.

I would suggest (re)arranging your data so that there’s a good value to search on (at the simplest {"has_target_key":true}). It’s good practice to lay out your data in ways that are easy to query. Think of it as providing an index that your app can look up more easily!

1 Like

Thanks for the response Meredydd. I can restructure.