Question

I want to select distinct not null values from the database. This works:

db((db.task.workspace==270) & (db.task.i0!=None)).select(db.task.i0, distinct=True)

But I need to specify the column as a string and I have it stored in the "col" variable. I tried this, but it shows a blank value:

db((db.task.workspace==270) & (col!=None)).select(col, distinct=True)

How can I fix this?

Was it helpful?

Solution

You can use dictionary notation to reference table fields, using the field name as the key:

db((db.task.workspace==270) & (db.task[col]!=None)).select(db.task[col], distinct=True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top