@Conor: This might be what I am looking for. I cannot try it right
now, but will reply to this thread in 3-4 hours.

Can you please point me to the documentation that discusses the
different ways of constructing select statements, where clauses, etc.
I have not seen the generative way before. I tried really hard on
Google, this forum specifically, stackoverflow, etc. The API
documentation is sufficient, I am sure; but is not "tutorial" like.

Thanks again. This is greatly appreciated.

-T

On Mar 31, 4:10 pm, Conor <conor.edward.da...@gmail.com> wrote:
> Tejaswi wrote:
> > I am not using sa.orm. I want to use only the sql expression syntax.
>
> > @Conor: I tried the dict approach. The problem is, I don't know how
> > many key value pairs I will have. I will have to use a map, or map* to
> > construct the full set of where clauses. This is the syntax I am not
> > able to figure out.
>
> How about this:
>
> clauses = [meta.c[key] == value for (key, value) in dict.iteritems()]
> select([table], and_(*clauses))
>
> or, generatively:
>
> s = select([table])
> for (key, value) in dict.iteritems():
>     s = s.where(meta.c[key] == value)
>
> -Conor
>
>
>
> > On Mar 31, 10:39 am, werner <wbru...@free.fr> wrote:
>
> >> On 31/03/2010 08:19, Tejaswi wrote:
>
> >>> I have a dict of keys to values which have to go into my where clause
> >>> with an and_.
>
> >>> Say dict = {"key1": value1, "key2": value2}
>
> >>> my select statement should look like select * from blah where key1 =
> >>> value1 and key2 = value2
>
> >>> I know this has to do with constructing the right where clause
> >>> element, but I cannot seem to find documentation on it.
>
> >>> select([table], meta.c.<columnname>  == value) doesn't take a variable
> >>> key.
>
> >>> Any help would be greatly appreciated.
>
> >> Are you using SA.orm?
>
> >> If yes, then you probably want to look at query.Query.filter  and/or
> >> query.Query.filter_by.
>
> >> Werner

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to