Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-03 Thread Robert Sudwarts
Hi Michael, I'm guilty of two over-simplifications in the code used in my example... Firstly, the substring property/column (with which I had a problem) applies to a subclass (using joined table inheritance) and the variable to which it applies is specified in its parent class. Hence, I started

[sqlalchemy] bidirectional self-referential many-to-many

2010-08-03 Thread Enrico
I'm trying to use the object association pattern from the doco. Is it the case that this requires departure from Declarative mode and is it wrong to mix with non-declarative? I looked at the example code optimized_al.py but it didn't seem to be exactly what I want. I want a symmetric relation for

Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 7:47 AM, Robert Sudwarts wrote: Hi Michael, I'm guilty of two over-simplifications in the code used in my example... Firstly, the substring property/column (with which I had a problem) applies to a subclass (using joined table inheritance) and the variable to which it

Re: [sqlalchemy] bidirectional self-referential many-to-many

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 3:37 AM, Enrico wrote: I'm trying to use the object association pattern from the doco. Is it the case that this requires departure from Declarative mode and is it wrong to mix with non-declarative? it is perfectly fine to mix non-declarative with declarative. However, it

Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-03 Thread Robert Sudwarts
Please see my comments below. Regards, Rob On 3 August 2010 14:05, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 3, 2010, at 7:47 AM, Robert Sudwarts wrote: Hi Michael, I'm guilty of two over-simplifications in the code used in my example... Firstly, the substring

[sqlalchemy] forcing an insert

2010-08-03 Thread Benjamin Peterson
Is there a way to force the ORM to insert a new row instead of updating? Something like the must_insert argument to model's save method in Django's ORM. The use case is I must create a unique session key (for a cookie) and want an error when the key isn't unique, so perhaps there's a better way?

Re: [sqlalchemy] forcing an insert

2010-08-03 Thread Wichert Akkerman
On 8/3/10 16:50 , Benjamin Peterson wrote: Is there a way to force the ORM to insert a new row instead of updating? Something like the must_insert argument to model's save method in Django's ORM. The use case is I must create a unique session key (for a cookie) and want an error when the key

Re: [sqlalchemy] forcing an insert

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 10:50 AM, Benjamin Peterson wrote: Is there a way to force the ORM to insert a new row instead of updating? Something like the must_insert argument to model's save method in Django's ORM. The use case is I must create a unique session key (for a cookie) and want an error

[sqlalchemy] mapping columns phone1, phone2, phone3 to a list-based property, phones

2010-08-03 Thread phrrn...@googlemail.com
Say you have a denormalized table with columns phone1, phone2, phone3 and you would like to map the class so that the .phones property is an iterable. e.g. if I have data like user_id, phone1, phone2, phone3 1, 1234, 5678, 9012 2, 3456,7890,1234 I would like to say something like for p in

[sqlalchemy] class definition missing from docs?

2010-08-03 Thread botz
http://www.sqlalchemy.org/docs/mappers.html#association-object refers to an Assocation class here: --- mapper(Parent, left_table, properties={ 'children':relationship(Association) }) mapper(Association, association_table, properties={ 'child':relationship(Child) }) --- but it doesn't

Re: [sqlalchemy] class definition missing from docs?

2010-08-03 Thread Michael Bayer
well neither is Parent and Child for that and the previous example if you want to get technical (or not even).will find some time to add them all in as that is a current project On Aug 3, 2010, at 1:36 PM, botz wrote: http://www.sqlalchemy.org/docs/mappers.html#association-object

Re: [sqlalchemy] mapping columns phone1, phone2, phone3 to a list-based property, phones

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 1:05 PM, phrrn...@googlemail.com wrote: Say you have a denormalized table with columns phone1, phone2, phone3 and you would like to map the class so that the .phones property is an iterable. e.g. if I have data like user_id, phone1, phone2, phone3 1, 1234, 5678, 9012 2,

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

2010-08-03 Thread Alvaro Reinoso
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 = session.query(Channel.title,

[sqlalchemy] func type_ not being used

2010-08-03 Thread Bryan
This returns a Decimal type for c2, which is what I want: c1 = literal(5, type_=Numeric) c2 = func.sum(c1, type_=Numeric) This returns a Float type for c2, but I'm telling c1 that it is a Numeric. How can I get a decimal returned when using an if function? c1 = func.if_(Table.foo != None,

Re: [sqlalchemy] func type_ not being used

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 2:56 PM, Bryan wrote: This returns a Decimal type for c2, which is what I want: c1 = literal(5, type_=Numeric) c2 = func.sum(c1, type_=Numeric) This returns a Float type for c2, but I'm telling c1 that it is a Numeric. How can I get a decimal returned when using an if

[sqlalchemy] Re: func type_ not being used

2010-08-03 Thread Bryan
Python 2.5.4 MySQL python 1.2.3c1 sqlalchemy 0.5.2 Here is the actual code. It references my object model etc so it won't run for you, but just in case I made a mistake converting it to a simplified version of the problem here it is: dollars = func.if_(EmpTime.actTotal != None,

[sqlalchemy] is it better to have 2 distinct sessions or just use a single session

2010-08-03 Thread razamatan
so our db setup is that we have both vertical and horizontal partitioning going on. first, is it possible to defined a session as a scoped, sharded session to achieve both? namely, define the shardedsession wrapped by a scoped session and simply have the various shard lookup functions (*chooser)

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

2010-08-03 Thread Michael Bayer
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 etc so it won't run for you, but just in case I made a mistake converting it to a simplified

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

2010-08-03 Thread jgs9000
Hi I'm relatively new to SQLAlchemy, so thanks in advance for any help with this issue. I'm trying to construct a class to model a legacy table which has a composite primary key which is also a composite foreign key referencing the composite primary key of a second table. I'm trying to define

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

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 10:24 PM, jgs9000 wrote: Hi I'm relatively new to SQLAlchemy, so thanks in advance for any help with this issue. I'm trying to construct a class to model a legacy table which has a composite primary key which is also a composite foreign key referencing the composite

Re: [sqlalchemy] is it better to have 2 distinct sessions or just use a single session

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 6:45 PM, razamatan wrote: so our db setup is that we have both vertical and horizontal partitioning going on. first, is it possible to defined a session as a scoped, sharded session to achieve both? namely, define the shardedsession wrapped by a scoped session and