Ohh, yes indeed (d'oh!). Thanks.

On 4/27/11, King Simon-NFHD78 <[email protected]> wrote:
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]]
>> On Behalf Of Luka Novsak
>> Sent: 27 April 2011 05:32
>> To: sqlalchemy
>> Subject: [sqlalchemy] Appending a where clause to a query
>>
>> The docs on Select's where() method say:
>>
>> > return a new select() construct with the given expression added to
>> its WHERE clause, joined to the existing clause via AND, if any.
>>
>
> Note: "return a new select() construct"
>
>> But this doesn't seem to happen.
>>
>> This is my code:
>>
>>     def posts_per_dow(self, start_date=None, end_date=None):
>>         q = select([func.date_part('isodow', t_posts.c.created_at),
>>                     func.count(t_posts.c.id)],
>>
>> t_posts.c.user_id==self.id).group_by('1').order_by('1')
>>
>>         if start_date: q.where(t_posts.c.created_at>=start_date)
>>         if end_date: q.where(t_posts.c.created_at<end_date)
>>
>> Only the first where clause is actually used when I execute the query.
>>
>> If I'm just going about it wrong, then how do I append a where clause
>> like this?
>>
>
> You need to store the return value of the 'where' method. eg:
>
> if start_date:
>     q = q.where(t_posts.c.created_at>=start_date)
> if end_date:
>     q = q.where(t_posts.c.created_at<end_date)
>
>
> Hope that helps,
>
> Simon
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>

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

Reply via email to