[sqlalchemy] Re: How to label text columns in a query

2009-08-28 Thread Mike Conley
Either of these works for the individual queries, but when combined in the union() or union_all() the result is still that the literal from the first query is used on all result rows q1 = session.query(A.data.label('somedata'), literal('A').label('source')) q2 =

[sqlalchemy] Re: Problem with defining relations between inherited classes

2009-08-28 Thread Tefnet Developers
Dnia 2009-08-27, czw o godzinie 10:51 -0400, Michael Bayer pisze: you can also set up primaryjoin using the actual table columns (i.e. PhysObject.locationId == Location.__table__.c.id). Thanks, that worked really well :). Now i am stuck with something else in this subject:

[sqlalchemy] Oracle issues

2009-08-28 Thread Teemu Yli-Elsilä
Hello, I read http://www.sqlalchemy.org/trac/wiki/06Migration and did not see a mention of any changes to type mapping or casting. I am currently using 0.5.5. While developing an application I found that generating tables from a declarative model resulted in undesirable / incorrect column

[sqlalchemy] Re: Oracle issues

2009-08-28 Thread Michael Bayer
Teemu Yli-Elsilä wrote: Hello, I read http://www.sqlalchemy.org/trac/wiki/06Migration and did not see a mention of any changes to type mapping or casting. I am currently using 0.5.5. While developing an application I found that generating tables from a declarative model resulted in

[sqlalchemy] Joining subqueries

2009-08-28 Thread Mike Conley
What is correct way to join two subqueries? The example is somewhat contrived, but illustrates the problem. SQL might look like this SELECT x.blah, y.blah FROM (SELECT id, data AS blah FROM a) AS x JOIN (SELECT id, data AS blah FROM b) AS y ON x.id = y.id Mapped classes are: class A(Base):

[sqlalchemy] Re: Joining subqueries

2009-08-28 Thread Michael Bayer
Mike Conley wrote: What is correct way to join two subqueries? The example is somewhat contrived, but illustrates the problem. SQL might look like this SELECT x.blah, y.blah FROM (SELECT id, data AS blah FROM a) AS x JOIN (SELECT id, data AS blah FROM b) AS y ON x.id = y.id Mapped

[sqlalchemy] Question Using MySQL Function Encode

2009-08-28 Thread Tim
I have a small project I am trying to finish and I ran into a hiccup. I saw the sqlachemy.sql.func object and decided to try to use it. Here is the code to get us on the same page. userPassword = 'thisisasalt'; insertDictionary = [{ 'user_name': user_name, 'user_pwd':

[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-28 Thread Seth
Mike, Thanks again for your posts. What about something like: q1 = DBSession.query(P1.id, P1.user_id, P1.type, P1.title, P1.body, P1.created, P1.updated, User.name).filter(P1.user_id==User.id) q2 = DBSession.query(P2.id, P2.user_id, 'P2', P2.title, P2.body, P2.created, P2.updated,

[sqlalchemy] Re: Issue with reflecting MySQL table with an explicit schema and a foreign key

2009-08-28 Thread Michael Bayer
Eric Naeseth wrote: SQLAlchemy seems to have an issue reflecting MySQL tables that have foreign keys when the table being reflected is not in the database specified in the connection string. Let's say I'm working on an app to manage a database named library, but that I also need access to

[sqlalchemy] Re: Problem with defining relations between inherited classes

2009-08-28 Thread Michael Bayer
Tefnet Developers wrote: Dnia 2009-08-27, czw o godzinie 10:51 -0400, Michael Bayer pisze: you can also set up primaryjoin using the actual table columns (i.e. PhysObject.locationId == Location.__table__.c.id). Thanks, that worked really well :). Now i am stuck with something else in

[sqlalchemy] Re: Somewhat complex union_all() question

2009-08-28 Thread Mike Conley
It works and will probably be OK. Using this style (query for user multiple times) in a really big database could lead to a performance problem depending on how the underlying database engine constructs a query plan. Try it and see how it goes. -- Mike Conley On Fri, Aug 28, 2009 at 2:22 PM,

[sqlalchemy] Re: How to label text columns in a query

2009-08-28 Thread Michael Bayer
Mike Conley wrote: Either of these works for the individual queries, but when combined in the union() or union_all() the result is still that the literal from the first query is used on all result rows q1 = session.query(A.data.label('somedata'), literal('A').label('source')) q2 =

[sqlalchemy] Re: wrong number of rows returned

2009-08-28 Thread DavidG
I guess I should restate the question. I have two tables: class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) mdata = Column(UnicodeText) bar = relation(Bar) def __repr__(self): return Foo(%r) % self.mdata class Bar(Base):

[sqlalchemy] Re: Issue with reflecting MySQL table with an explicit schema and a foreign key

2009-08-28 Thread Eric Naeseth
Michael Bayer wrote: Eric Naeseth wrote: SQLAlchemy seems to have an issue reflecting MySQL tables that have foreign keys when the table being reflected is not in the database specified in the connection string. Let's say I'm working on an app to manage a database named library, but

[sqlalchemy] Re: Problem with defining relations between inherited classes

2009-08-28 Thread Tomasz Jezierski - Tefnet
Dnia 2009-08-28, Pt o godzinie 10:51 -0400, Michael Bayer pisze: Tefnet Developers wrote: Dnia 2009-08-27, czw o godzinie 10:51 -0400, Michael Bayer pisze: you can also set up primaryjoin using the actual table columns (i.e. PhysObject.locationId == Location.__table__.c.id).

[sqlalchemy] how to make unique constrain within ORM

2009-08-28 Thread vkuznet
Hi, I created ORM classes and can't find out a way to make an UniqueConstraint for two columns. Do we have an example elsewhere? When I used UniqueConstraint from sqlachemy.schema inside of ORM class it does nothing, so it's not defined in a table. In particular here is my class class

[sqlalchemy] Re: Problem with defining relations between inherited classes

2009-08-28 Thread Michael Bayer
Tomasz Jezierski - Tefnet wrote: Awkward column_property is because of exception you'll get if try to set Column without column_proprerty around it: --- sqlalchemy.exc.ArgumentError: Column 'PhysObject.locationId' is not represented in mapper's table. Use the `column_property()` function

[sqlalchemy] Simple example of checking for containment

2009-08-28 Thread Victor Ng
I can't seem to figure out how to tell sqlalchemy to do something like : UPDATE Foo SET turnover = 1 WHERE EXPLANATION NOT IN(SELECT Reason FROM mbsIsTurnoverXLAT where Datasource ='blah' and Isturnover=0) AND DATASOURCE = 'blah' The not in clause is the part that's tripping me up. I'm not

[sqlalchemy] Re: Problem with defining relations between inherited classes

2009-08-28 Thread Michael Bayer
Tomasz Jezierski - Tefnet wrote: Awkward column_property is because of exception you'll get if try to set Column without column_proprerty around it: --- sqlalchemy.exc.ArgumentError: Column 'PhysObject.locationId' is not represented in mapper's table. Use the `column_property()` function to

[sqlalchemy] Re: Problem with defining relations between inherited classes

2009-08-28 Thread Michael Bayer
Tomasz Jezierski - Tefnet wrote: --- sqlalchemy.exc.ArgumentError: Column 'PhysObject.locationId' is not represented in mapper's table. Use the `column_property()` function to force this column to be mapped as a read-only attribute. ticket # 1523 has a patch that allows this approach to

[sqlalchemy] Re: how to make unique constrain within ORM

2009-08-28 Thread Mike Conley
Constraints are defined in __table_args__ try: __table_args__ = ( UniqueConstraint('api_id', 'daskey_id', name='uix_1'), {'mysql_engine':'InnoDB'}) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[sqlalchemy] Re: wrong number of rows returned

2009-08-28 Thread DavidG
Here is what I am doing now (even forgetting the limit): - username = u'hal' subq = SES.query(Bar).filter(Bar.username == username).\ subquery() valias = aliased(Bar, subq) q = SES.query(Foo, valias).order_by(Foo.mdata).\ outerjoin(Foo.bar, valias) recs = q.all()

[sqlalchemy] eagerload polymorphic object's relations, single table inheritance

2009-08-28 Thread Jae Kwon
I've seen similar discussions here, but it's been a while so perhaps things have changed. class Foo(Base): __tablename__ = 'foo' type = Column(Integer) __mapper_args__ = {'polymorphic_on': type} ... class BarFoo(Foo): __mapper_args__ = {'polymorphic_identity': 1} bar_id =

[sqlalchemy] Autoflush setting

2009-08-28 Thread gizli
Hi all, I have a pretty basic question about autoflush that I could not find an answer to. By default, in sessionmaker, this is set to true. However, I have this basic scenario where my transaction involves inserting objects into session and querying for some others: add(o1) query(SomeObject)

[sqlalchemy] Re: Autoflush setting

2009-08-28 Thread gizli
Okay. I believe this is my mistake. I just wrote a simple test program and saw that the other threads should not see o1 or o2 until commit since I am using scoped_session. I guess there is another reason for the behavior I am seeing. On Aug 28, 10:05 pm, gizli mehm...@gmail.com wrote: Hi all,