RE: [sqlalchemy] Re: To select only some columns from some tables using session object, relation many-to-many

2010-08-04 Thread King Simon-NFHD78
Alvaro Reinoso wrote: It works out, thank you! How could I just retrieve some columns from both tables? For example, if I try to select some columns from Item and Channel, I get class 'sqlalchemy.util.NamedTuple' when I'd like to get a channel type with its items: result =

[sqlalchemy] polymorphic query - anon_1, anon_2 ... can they be used?

2010-08-04 Thread Richard Kuesters
hi all, in a polymorphic query, after a 'print' command i realized that SA generates some columns named 'anon_X', which can be helpful for me. the question is: 1. is it safe to use those anon_X columns to refine my query? --- regarding this, my concern is that once the polymorphic query is done

[sqlalchemy] SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Gregg Lind
suppose: summary_table = Table( 'summary', metadata, Column('ts',Integer, index=True, nullable=False), Column('url',String, index=True, nullable=False), Column('hits',Integer, nullable=False), PrimaryKeyConstraint('ts','url','hits',name='summary_pk'),

[sqlalchemy] Basic query questions ...

2010-08-04 Thread Michael Hipp
Hello, a couple of really basic questions ... 1) How do I write a query beforehand that will be evaluated later at some other place in the code? (Note that the session hopefully won't exist until that later time.) Also, certain parameters may need to be passed to the query at eval time (e.g.

[sqlalchemy] Re: func type_ not being used

2010-08-04 Thread Bryan
Same behavior with 0.6.3. On Aug 3, 4:17 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 3, 2010, at 5:00 PM, Bryan wrote: Python 2.5.4 MySQL python 1.2.3c1 sqlalchemy 0.5.2 just curious can you try with SQLA 0.6.3 ? Here is the actual code.  It references my object model

Re: [sqlalchemy] SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Michael Bayer
On Aug 4, 2010, at 10:34 AM, Gregg Lind wrote: suppose: summary_table = Table( 'summary', metadata, Column('ts',Integer, index=True, nullable=False), Column('url',String, index=True, nullable=False), Column('hits',Integer, nullable=False),

Re: [sqlalchemy] Re: func type_ not being used

2010-08-04 Thread Michael Bayer
nothing wrong with the code I see, and I am noticing that to recreate your test is taking me longer than one minute, so please provide a fully reproducing test case. On Aug 4, 2010, at 11:14 AM, Bryan wrote: Same behavior with 0.6.3. On Aug 3, 4:17 pm, Michael Bayer

Re: [sqlalchemy] polymorphic query - anon_1, anon_2 ... can they be used?

2010-08-04 Thread Michael Bayer
On Aug 4, 2010, at 10:07 AM, Richard Kuesters wrote: hi all, in a polymorphic query, after a 'print' command i realized that SA generates some columns named 'anon_X', which can be helpful for me. the question is: 1. is it safe to use those anon_X columns to refine my query? ---

[sqlalchemy] Re: func type_ not being used

2010-08-04 Thread Bryan
OK, I'll put together a case later today. On Aug 4, 8:24 am, Michael Bayer mike...@zzzcomputing.com wrote: nothing wrong with the code I see, and I am noticing that to recreate your test is taking me longer than one minute, so please provide a fully reproducing test case. On Aug 4, 2010,

Re: [sqlalchemy] polymorphic query - anon_1, anon_2 ... can they be used?

2010-08-04 Thread Richard Kuesters
thanks Michael, that's what i have in mind. since anon_N can't be used, i was thinking if they can be named or, in other cases, the sql that generates an anon_N can be extracted? ps: the object that contains these anon_N columns is a orm.Query object created from a polymorphic mapper with

Re: [sqlalchemy] polymorphic query - anon_1, anon_2 ... can they be used?

2010-08-04 Thread Michael Bayer
On Aug 4, 2010, at 11:51 AM, Richard Kuesters wrote: thanks Michael, that's what i have in mind. since anon_N can't be used, i was thinking if they can be named or, in other cases, the sql that generates an anon_N can be extracted? ps: the object that contains these anon_N columns is a

[sqlalchemy] Re: SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Gregg Lind
Thanks for the advice! One minor nit. At least in my experience, str(bound query) doesn't fill the params, or do quoting properly. Here is a demonstration: fake_table = Table( 'faketable', metadata, Column('ts',Integer, index=True, nullable=False),

Re: [sqlalchemy] Re: SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Michael Bayer
On Aug 4, 2010, at 1:26 PM, Gregg Lind wrote: Thanks for the advice! One minor nit. At least in my experience, str(bound query) doesn't fill the params, or do quoting properly. Here is a demonstration: fake_table = Table( 'faketable', metadata, Column('ts',Integer,

[sqlalchemy] Re: SQL Expression lang; change table in from clause after query construction; copying queries; printing queries with filled params

2010-08-04 Thread Gregg Lind
Thank you for the more detailed explanation! I will do some experiments with it! Gregg On Aug 4, 12:39 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 4, 2010, at 1:26 PM, Gregg Lind wrote: Thanks for the advice! One minor nit.  At least in my experience, str(bound query)

[sqlalchemy] Problems with the relation one to many

2010-08-04 Thread Alvaro Reinoso
Hello, I got this error when I've tried to relate some classes: UnmappedClassError: Class 'zeppelinlib.user.UserTest.User' is not mapped I don't get errors when I have relation many-to-many. This is my file where I store all the User classes. user_channels = Table(

[sqlalchemy] joined queries across databases and declarative_base

2010-08-04 Thread Patrice Munger
Hello! I have two classes that are mapped to tables from different databases. The classes are defined with declarative_base. I can query each class individually, but a joined query fails. Here is an example: from sqlalchemy.orm import sessionmaker import sqlalchemy as sa from

[sqlalchemy] strange error with dynamic_loader

2010-08-04 Thread Jon Nelson
It seems as though attributes which are dynamic_loaders cannot be told to eagerly load subattributes which are themselves dynamic_loaders. IE, A has dynamic_loader for instances of B, which has dynamic_loader for instances of C. Assuming we have an instance of A, this works fine: query =

[sqlalchemy] Re: Problems with the relation one to many

2010-08-04 Thread Alvaro Reinoso
Solved it. I'm using grok as CMS and didn't realize I have to grok every component every time when I use it. That's why I got that error. Thanks anyway! On Aug 4, 4:27 pm, Alvaro Reinoso alvrein...@gmail.com wrote: Hello, I got this error when I've tried to relate some classes:

Re: [sqlalchemy] strange error with dynamic_loader

2010-08-04 Thread Michael Bayer
On Aug 4, 2010, at 5:31 PM, Jon Nelson wrote: It seems as though attributes which are dynamic_loaders cannot be told to eagerly load subattributes which are themselves dynamic_loaders. that is correct. dynamic loaders are not backed by in-memory collections, and no alternate loader

[sqlalchemy] inheritance and column_property() - subqueries are being limited

2010-08-04 Thread Zippy P
I have a single-table inheritance setup: class Device(Base): __tablename__ = 'devices' devtype = Column(Unicode(20), nullable = False) mac = Column(Unicode(128), primary_key = True) ... class PC(Device): __mapper_args_ = {'polymorphic_identity':u'PC'} switch_mac =

[sqlalchemy] Re: inheritance and column_property() - subqueries are being limited

2010-08-04 Thread SQLAlchemy User
...and I've figured out a workaround: in Switch(Device): pcs = relationship('PC', primaryjoin = 'Switch.mac == PC.switch_mac', lazy='dynamic') Now, switch.pcs.count() works :) S. On Aug 4, 5:00 pm, Zippy P sqlalchemyu...@gmail.com wrote: I have a single-table inheritance setup: class

[sqlalchemy] Re: declarative autoloading table class with composite foreign/primary key

2010-08-04 Thread jgs9000
Michael thanks very much for your helpful advice - the problem seems to actually involve the autoloading of the table in question. The table structure is as follows: CREATE TABLE wcs ( image_id INTEGER NOT NULL, amp INTEGER

Re: [sqlalchemy] Re: declarative autoloading table class with composite foreign/primary key

2010-08-04 Thread Michael Bayer
On Aug 4, 2010, at 9:05 PM, jgs9000 wrote: Michael thanks very much for your helpful advice - the problem seems to actually involve the autoloading of the table in question. so there's a small bug that is easy to fix, that is ticket #1865 and it is fixed in r742bd985b4e0, latest tip, so

[sqlalchemy] create_all() fails silently

2010-08-04 Thread Michael Hipp
Can someone tell me why this code won't create any tables? The tables are defined in another file that calls declarative_base(). I presume the problem is that it doesn't know which tables to create. If so, how do I tell it what tables to create? Base = declarative_base() database =

Re: [sqlalchemy] create_all() fails silently

2010-08-04 Thread Mike Conley
On Wed, Aug 4, 2010 at 9:39 PM, Michael Hipp mich...@hipp.com wrote: Can someone tell me why this code won't create any tables? The tables are defined in another file that calls declarative_base(). I presume the problem is that it doesn't know which tables to create. If so, how do I tell it