Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with .contains() when passing list as argument #685

Closed
unle70 opened this issue Apr 8, 2022 · 1 comment
Closed

problem with .contains() when passing list as argument #685

unle70 opened this issue Apr 8, 2022 · 1 comment

Comments

@unle70
Copy link

unle70 commented Apr 8, 2022

I was trying to use .contains() and compared 2 cases:

a. Passing a DAL field (db.table.column) as parameter to the .contains()
b. Passing a list where one item is a DAL field ( ['a', 'b', db.table.column] ) to the .contains()

In case 'a' everything works as expected.
In case 'b' the column name is set in the SQL to be just a string (quoted) and not working properly.

I hope what I'm trying to do in 'b' above can be made to work.

Thanks,
Udi

@mdipierro
Copy link
Contributor

The proper use of contains is db.table.field.contains(value) a value should be a string a number (for list of integers) or a string. I am amazed and happy that it works when the value is another field, although that may not be supported by all database engines. Passing a list is not supported but you can do:

OR = lambda a,b: a|b
query = reduce(OR, map(db.table.column.contains, ['a', 'b', 'c']))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants