On Aug 16, 2010, at 11:21 AM, bekozi wrote:

> Is it possible to work with set-returning functions in SQLAlchemy
> without using raw SQL? For example, the PostgreSQL/PostGIS function
> ST_Dump (http://bit.ly/culek7) returns a “geometry_dump" set. Using
> ST_Dump in raw SQL goes something like:
> 
>       SELECT
>         ST_Dump(ST_Intersection(data_table1.geom,data_table2.geom)).geom AS
> geom...
> 
> In SQLAlchemy an attempt to construct this unsurprisingly yields an
> attribute error:
> 
>       
> session.query(func.ST_Dump(functions.intersection(Data1.geom,Data2.geom).geom.label('geom'))
>       AttributeError: 'Function' object has no attribute 'geom'

any SQL you want can be made available with Python expressions using @compiles:

from sqlalchemy import *
from sqlalchemy.sql import ColumnElement, column

from sqlalchemy.ext.compiler import compiles

class geom(ColumnElement):
    def __init__(self, base):
        self.base = base
        
@compiles(geom)
def compile(expr, compiler, **kw):
    return compiler.process(expr.base) + ".geom"

data1, data2 = column('data1'), column('data2')
print select([func.ST_Dump(
            geom(func.intersection(geom(data1),geom(data2)))
            ).label('geom')])

> Curious if anyone knows a solution! A search for using set-returning
> functions in SQLAlchemy yielded no obvious solution...

any reason you aren't using GeoAlchemy ?






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