Thank you.

However, when the types of user (defined as Table()) and adults (the
select object) are different types. I would like the adults variable
to be of the same type as user.
Is this possible?

Thanks

On Apr 9, 1:18 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote:
> Acm wrote:
> > I am working with SQLAlchemy 0.4.5
>
> > I have this table definition:
>
> > table1_def = Table('mytablename', metadata, schema='myschemaname',
> > autoload=True)
>
> > Now I would like a view on this table such that I only load the
> > records where column1 = 0.
>
> > I would like to define my view something as
>
> > view_table1_def = Table('mytablename', metadata,
> > schema='myschemaname', autoload=True, where(column1 = 0))
>
> > How can I define the view for table1 to load only data for a certain
> > condition?
>
> You just create a selectable and then can it use like a table object in
> SQLAlchemy. Like this.
>
> -- Gerhard
>
> from sqlalchemy import *
>
> engine = create_engine("sqlite:///:memory:")
> metadata = MetaData(engine)
>
> user = Table("person", metadata,
>      Column("person_id", Integer, primary_key=True),
>      Column("firstname", String(20), nullable=False),
>      Column("age", Integer, nullable=False),
> )
>
> metadata.create_all()
> user.insert().execute(firstname="Gerhard", age=31)
> user.insert().execute(firstname="Lara", age=47)
> user.insert().execute(firstname="Benny", age=13)
>
> adults = user.select(user.c.age >= 18)
>
> print adults.select().execute().fetchall()
--~--~---------~--~----~------------~-------~--~----~
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