Searching datatable where Media is not None

I hope a quick question…

I’m trying to search a datatable for all rows with content in the Media column.

I’ve tried:

rows = app_tables.my_table.search(MediaColumn=q.not_(None))

But I’m getting an error:

TableError: 'Cannot use a Media object as a search query'

Any ideas?

Thanks

Dan

I’ve hit this previously. I ended up storing a hash of the media object in a separate text column and searching that instead.

In that case, I also needed to search for equality, so the hash was necessary. If you only need existence, a boolean column would work.

Alternatively, might a generator expression work here? Get the search result for all rows and then create a generator expression on top of that to filter out the rows without media.

Something like:

all_rows = app_tables.my_table.search()
result = (r for r in all_rows if r["MediaColumm"] is not None)

(I’m on my phone so can’t try that for real right now)

1 Like

Hi Owen, thanks for your responses.

The generator function works but is cumbersome with the amount of rows I need to deal with (the majority of the rows DON’T have media).

Sounds like no elegant solution here!

Dan

How is it cumbersome? They are both generators, so should be decently efficient.