Heh, that was easy. I'm curious now, though, why it can't find the primary key with the revised select you gave. (Works fine when I manually tell the mapper what to use.)
On 10/30/06, Michael Bayer <[EMAIL PROTECTED]> wrote: > interesting ! that answers that question (i.e., the question above the > assertion statement....) changed it to a "continue" in rev 2072. > > however, your mapping isnt going to work with those textual columns anyway > since it cant intelligently construct an aliased select from it, you have to > say: > > s = select([b.c.published_year, func.count('*').label('n')], from_obj=[b], > group_by=[b.c.published_year]) > > i guess you already knew that. > > > On Oct 30, 2006, at 6:19 PM, Jonathan Ellis wrote: > > > from sqlalchemy import * > > > > > e = create_engine('sqlite:///:memory:', echo=True) > > > > > md = BoundMetaData(e) > > sql = """ > > CREATE TABLE books ( > > id integer PRIMARY KEY, -- auto-SERIAL in sqlite > > title text NOT NULL, > > published_year char(4) NOT NULL, > > authors text NOT NULL > > ) > > """ > > e.execute(sql) > > > > > b = Table('books', md, autoload=True) > > s = select(["published_year", "count(*) as n"], from_obj=[b], > > group_by=[b.c.published_year]) > > s = s.alias('years_with_count') > > > > > class YearWithCount(object): > > pass > > > > > mapper = mapper(YearWithCount, s) > > session = create_session() > > q = session.query(YearWithCount) > > q.select_by(published_year='2006') > > > > -- Jonathan Ellis http://spyced.blogspot.com --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy -~----------~----~----~----~------~----~------~--~---