On 2019-03-19 21:12, Brosefski wrote:
> I'm not sure how I would do this but I was wondering if there was a
> programmatic way to select items from a list.
> 
> Ie:  I have a table:
> table1 = Table("table1", "public")
> 
> and I have a list of fields names like so:
> ["field1", "field2"]
> 
> I would like to be able to feed that list rather than type out the select
> explicitly.  What this allows me change what I'm selecting dynamically.

Yes you can. You could use getattr on Table instance but there is a risk
that the attribute name collide with an attribute of the class.
So the best option is to instantiate columns:

    columns = [Column(table1, f) for f in ["field1", "field2"]]
    query = table1.select(columns)

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: [email protected]
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"python-sql" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to