first thing, "wlt" is a view?  thats very surprising that "autoload"  
would work with that...but then im not so famliar with the specifics  
of postgres views.

if your mapper is not getting the proper primary key columns from its  
mapped table, you can use the "primary_key" argument to mapper()  
itself and force the columns that should be used for the pk.

On Oct 16, 2006, at 11:42 AM, artee wrote:

>
> Hi
>
> I've been using SQLAlchemy for some queries based on the SQL views
> (Postgres).
> The problem is in results returned from session.query.
> Depending on the method (session or not) for a table with a lot of
> items results are not the same:
>
> metadata = BoundMetaData('postgres://blabla')
> wlt = Table('wlt', metadata, Column('id', String(), primary_key =
> True), autoload=True)
> class Wlt(object): pass
> Wlt.mapper = mapper(Wlt, wlt)
>
> order = [asc(wlt.c.somecolumn)]
> items = wlt.select(w, order_by=order, limit=5).execute()
> print 'Old method: %d' % len(list(items)) # 5 items
>
> session = create_session()
> items = session.query(Wlt).select(w, order_by=order, limit=5)
> session.flush()
> print 'New method: %d' % len(list(items)) # 2 items !
>
> I supose that problem can be in primary key definition. SQL view  
> does't
> have a primary key, the primary key is taken from 'FROM' table key.
> SQL statements created by the engine are different:
> SELECT wlt.id, /**/ FROM wlt ORDER BY wlt.somecolumn ASC LIMIT 5 in  
> the
> first case
> and SELECT wlt.id AS wlt_id, /**/ FROM wlt ORDER BY wlt.somecolumn ASC
> LIMIT 5 in the second
> Any ideas ?
>
> Cheers,
> Artur
>
>
> >


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

Reply via email to