On May 21, 2014, at 2:02 AM, gbr <[email protected]> wrote: > Thanks to both of you for the pointers. Unfortunately, the way this is meant > to work is not really an option for me. > > At current, I do > > sel2 = sel.where(literal("name = '%s'" % thing)) > > to get around using a column reference. This works for now, but I was hoping > for a better solution. I might have a look at `_raw_columns` as suggested to > at least verify the existence of the columns to do something like > > def do_query(**keyvalues): > sel = create_complicated_query_with_lots_of_joins_and_labels() > a = and_() > for k, v in keyvalues.items(): > column = make_column(k, sel) # use _raw_columns in here to extract the > column reference of `k`? > a.add(column == v) > return sel.where(a)
there's always a column reference which can provide that value. Your code knows about the string "name", it should also know from which source of rows this name is to be selected. with "<something>.c.name", "<somehting>" should be whatever was used to provide that FROM clause within the select. you can look in select.froms for it, or select.inner_columns for the column itself, though with only the word "name" you really don't know if its table1.c.name or table2.c.name. you can also look in sel.c.name.proxy_set for columns that are being proxied but again this is a place where you'd have to do some heuristics/guessing in order to get the right column. I'd suggest that the code be organized such that it's able to track the source selectables placed into the query it's building, as it stands it is losing track of important information. Feel free to share more specifics. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
