the func. call is a SQL expression which can't be bound to a bind  
parameter.  that has to stay in the values() clause.  e.g.
        
        table.insert().values(location=f, id=97).execute(), or

        table.insert().values(location=f).execute(id=97).

if you wanted everything inside of 'f' to be bound:

        table.insert().values(location=func.GeomFromText(bindparam('a'),  
bindparam('b')).execute(id=97, a='POINT(2,3)', b=4326).

Also I've built an ORM extension for postgis which is incomplete but  
demonstrates how to round trip and create PostGIS expressions in a  
clean way, thats in the distribution in examples/postgis/postgis.py .


On Feb 20, 2009, at 4:03 PM, quaker4lyf wrote:

>
> Hello,
>
> I need to query, insert, update and delete from already existing
> PostGIS tables.
>
> After much trial and error, nothing worked. Then I came across this
> message:
> http://groups.google.com/group/sqlalchemy/msg/424d9aa10d30abaf
>
> Following that, I've confirmed that the following works:
>
> f = func.GeomFromText('POINT(-118.0 34.0)',4326)
> ins = tbl_test.insert().values(id=97, location=f)
> conn = engine.connect()
> trans = conn.begin()
> conn.execute(ins)
> trans.commit()
> conn.close()
>
> which is nice, but I like to work with connectionless or implicit
> execution (as described in SQLAlchemy 0.5.3 Documentation). So I
> tried:
>
> tbl_test.insert().execute(id=42, location=f)
>
> but it doesn't work. The error returned was:
>
> sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt
> 'INSERT INTO tbl_test (id, location) VALUES (%(id)s, %(location)
> s)' {'id': 42, 'location': <sqlalchemy.sql.expression.Function at
> 0x830dd8c; GeomFromText>}
>
> So I suspect this has to do with how slqalchemy understands my table
> schema?
>
> I currently am declaring the table as
>
> tbl_test = Table('tbl_test', self.metadata, Column('event_id',
> Integer), Column('location', Geometry(2, 4326), nullable=False))
>
> where Geometry is copied and pasted from some post found using Google:
>
> class Geometry(TypeEngine):
>    """Base PostGIS Geometry column type"""
>
>    name = 'GEOMETRY'
>
>    def __init__(self, dimension, srid=-1):
>        self.dimension = dimension
>        self.srid = srid
>
>    def bind_processor(self, dialect):
>        def process(value):
>            return value
>        return process
>
>    def result_processor(self, dialect): #not used yet
>        def process(value):
>                return value
>        return process
>
>
> Can anyone help? According to Michael Bayer in that old post, the
> connectionless statement should work.
>
> Thank you
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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