On Dec 13, 2010, at 12:12 PM, Ralph Heinkel wrote:

> Hi Michael,
> 
> this drop-in is great, it does exactly what I need.  It just has a
> small problem in that the variable 'rownum' is not allowed in oracle,
> it produces a
> DatabaseError: (DatabaseError) ORA-00923: FROM keyword not found where
> expected
> Replacing 'rownum' with 'ora_rn' or something similar fixes this
> problem.
> 
> On Dec 9, 5:25 pm, Michael Bayer <[email protected]> wrote:
>> 
>> the recipe for built in ROW_NUMBER() for LIMIT/OFFSET should be a drop in 
>> and is at:
>> 
>> http://www.sqlalchemy.org/trac/wiki/UsageRecipes/WindowFunctionsByDef...
>> 
>> applying to certain domain objects only would be a little more involved.   
>> You'd probably want to place some kind of "hint" on the statement that the 
>> custom > compiler picks up on, or perhaps it looks at the table being 
>> selected to make this determination.
> 
> What would be the safest way to get access to the table/model for
> which the query was created?
> I found that  "element._froms[0]" is a pointer to my table, is this a
> good/stable/portable way to get hold of it? This way I could just
> instrument my model (aka hint) so see whether I need the ROW_NUMBER
> approach or not.

Theres different ways to locate "tables" in the selectable depending on what 
you want.   In this case it might be best for you to look at the 
_order_by_clause attribute to see which tables or selectables are being ordered 
upon, since those are the columns/tables that are impacted by the ROW NUMBER 
operation.  select() itself has a public "froms" member as well.   This member 
includes all FROM clauses including those that might not render if the select 
is embedded within another one where correlation is taking place - if you 
wanted to filter more carefully like that I'd emulate what 
compiler.py:SQLCompiler.visit_select() is doing.



> 
> Ralph
> 
> -- 
> 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