[storm] setting a database timestamp

James Henstridge james at jamesh.id.au
Wed Apr 22 03:02:17 BST 2009


On Wed, Apr 22, 2009 at 9:31 AM, Martin DeMello <martindemello at gmail.com> wrote:
> On Wed, Apr 22, 2009 at 6:44 AM, James Henstridge <james at jamesh.id.au> wrote:
>> On Wed, Apr 22, 2009 at 8:43 AM, Martin DeMello <martindemello at gmail.com> wrote:
>>> How do I access postgresql's CURRENT_TIMESTAMP function from storm?
>>> That is, I want a table with a datetime column updated with the
>>> server's current time, not datetime.now() on the client.
>>
>> Try the following:
>>
>> from storm.expr import SQL
>>
>> CURRENT_TIMESTAMP = SQL("CURRENT_TIMESTAMP")
>
> Nice. And for the benefit of anyone googling this, I solved the second
> part of my problem too -
>
> store.find(User, (SQL("CURRENT_TIMESTAMP") - User.last_updated > '1 00:00:00'))
>
> will find all users who haven't been active in the last day.

Yep.  You could even use timedelta(days=1) in that expression if you wanted.

One thing to keep in mind is that the (SQL(...) - User.last_updated >
...) expression will look like a truth value if you use it in a Python
if statement rather than passing it to Storm.  This is because the
operator overloading on the expression objects causes the operations
to form an expression tree object rather than resulting in True or
False.

James.



More information about the storm mailing list