[storm] SQL to Storm
Brad Allen
ballen at zeomega.com
Tue Sep 15 14:53:53 BST 2009
This question and answer seem like a good candidate to add to the FAQ...
On Mon, Sep 14, 2009 at 8:45 PM, James Henstridge <james at jamesh.id.au>wrote:
> On Mon, Sep 14, 2009 at 7:16 PM, Eduardo Willians<edujurista at gmail.com>
> wrote:
> > Did I say something wrong or stupid?
>
> Nope. No one got round to answering the question though :( I'll
> rectify that now.
>
> >
> > 2009/9/9 Eduardo Willians <edujurista at gmail.com>:
> >> Is there a stormic way to execute the following SQL statement?
> >>
> >> store.execute("""SELECT MAX(id) FROM gear.op WHERE CAST(id AS
> >> character) LIKE '9%';""").get_one()
> >>
> >> I'm using postgres.
>
> There isn't anything in Storm to generate the WHERE clause you've used
> here. However, you can insert arbitrary SQL into an expression using
> the SQL() operator. Something like this:
>
> result = store.find(GearOp, SQL("CAST(gear.op.id AS character) LIKE
> '9%'"))
> maximum = result.max(GearOp.id)
>
> You can combine SQL() with other Storm expression objects in pretty
> much any situation. The one downside is that they won't give you the
> "auto tables" behaviour where Storm guesses what tables need to be
> used for a given query. It wasn't required in the above, because the
> table used in the SQL() expression is already referenced.
>
> If you want to keep the "auto tables" behaviour in other cases, you
> can manually specify what tables the expression uses. Something like:
>
> SQL("...", tables=[GearOp])
>
> I hope this helps,
>
> James.
>
> --
> storm mailing list
> storm at lists.canonical.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/storm
>
--
ZeOmega
Open Minds' Open Solutions
3010 Gaylord Parkway, Ste. 210
Frisco TX, 75034
http://www.zeomega.com
Brad Allen
214-618-9880 (ext. 8006)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20090915/d7d073ba/attachment-0002.htm
More information about the storm
mailing list