[sqlalchemy] selecting an amibiguous column, but not caring from which table

2011-09-19 Thread Moshe C.
Hi, I have the following situation: There are two tables, A and B , both of which have an id column. In a certain part of the code I have an ORM query object. That query object is returned by some function and I have no apriori knowledge of its structure. I am assured, though that there will be

[sqlalchemy] Selecting the right table instance in a self referential join

2011-07-27 Thread Moshe C.
I have the following mapper: orm.mapper(Xxx,xxx_table, inherits=Resource, polymorphic_identity=u'xxx', properties={'children' : orm.relation(Xxx, backref=orm.backref('parent', remote_side=[Xxx.c.id]),

[sqlalchemy] Re: Selecting the right table instance in a self referential join

2011-07-27 Thread Moshe C.
I seem to have solved it by aliasing the first instance too query = sqlalchemy.orm.query(Xxx) *alias = SA.orm.aliased(Xxx)* query = query.join(*(alias,'parent')*, aliased=True) query = query.filter(some criterion) But this

[sqlalchemy] Re: What is the Sqlalchemy syntax for having ORDER BY and LIMIT on DELETE

2011-06-15 Thread Moshe C.
other processes get a chance at querying. The ORDER BY is just for aesthetics, so that I always delete the oldest ones first and not create holes, but I can live without it. On Jun 14, 2:32 pm, Rami Chowdhury rami.chowdh...@gmail.com wrote: On Mon, Jun 13, 2011 at 15:42, Moshe C. mos

[sqlalchemy] What is the Sqlalchemy syntax for having ORDER BY and LIMIT on DELETE

2011-06-13 Thread Moshe C.
Hi, I am using Sqlalchemy 0.6.5 . How do I generate the following statement usin Sqlalchemy expressions (not ORM). DELETE FROM table ORDER BY timestamp LIMIT 10; TIA -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send

[sqlalchemy] Re: What is the Sqlalchemy syntax for having ORDER BY and LIMIT on DELETE

2011-06-13 Thread Moshe C.
/compiler.html On Jun 13, 2011, at 10:10 AM, Moshe C. wrote: Hi, I am using Sqlalchemy 0.6.5 . How do I generate the following statement usin Sqlalchemy expressions (not ORM). DELETE FROM table ORDER BY timestamp LIMIT 10; TIA -- You received this message because you

[sqlalchemy] migrating from 0.4 to 0.6 - PrimaryKeyConstraint.keys()

2011-01-04 Thread Moshe C.
What replaces the keys() method of PrimaryKeyConstraint that existed in 0.4 ? TIA -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to

[sqlalchemy] distinct on two fields with a count

2010-03-11 Thread Moshe C.
How do I write an expression (in sqlalchemy 0.4.6) that will generate the following expression: select count(distinct field1, field2) from tableA; I know how to do it for one field and I know how to do it with no count using distinct=True, but not this combination. -- You received this

[sqlalchemy] needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.
Trying to find out if I hit a bug or it is me doing something wrong. Using version 0.4.6 when creating an object and then calling session.save() I get: Instance 'res...@-0x486e4074' is already persistent It works save_or_update() with, but I don't see why I should use that. I did read that

[sqlalchemy] Re: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.
Thanks. Given that I am not going to upgrade very soon, is it right to conclude that there was a bug in 0.4.6, or is my usage wrong? On Jun 3, 5:28 pm, Michael Bayer mike...@zzzcomputing.com wrote: Moshe C. wrote: Trying to find out if I hit a bug or it is me doing something wrong. Using

[sqlalchemy] Re: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.
for a related object, makes the Resume object not transient anymore? On Jun 3, 8:56 pm, Michael Bayer mike...@zzzcomputing.com wrote: Moshe C. wrote: Thanks. Given that I am not going to upgrade very soon, is it right to conclude that there was a bug in 0.4.6, or is my usage wrong

[sqlalchemy] Re: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.
. There is a relation between the objects, but it is not clear how querying on another object makes the Resume object non- transient. On Jun 3, 10:55 pm, Michael Bayer mike...@zzzcomputing.com wrote: Moshe C. wrote: Well, I thought it was transient. If you refer to the code in the first post: your

[sqlalchemy] Re: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.
Weird, the first assertion already fails, but I am not using ScopedSession.mapper. See the code in the first post. On Jun 3, 11:28 pm, Michael Bayer mike...@zzzcomputing.com wrote: easy way to ensure things are working as expected: Moshe C. wrote: In code:         t = Model.Resume

[sqlalchemy] Re: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.
): Model.session.save_or_update(obj) def flush(self): Model.session.flush() def delete(self, obj): Model.session.delete(obj) def clear(self): Model.session.clear() On Jun 3, 11:47 pm, Michael Bayer mike...@zzzcomputing.com wrote: Moshe C. wrote: Weird, the first assertion

[sqlalchemy] Filtering by count of child object

2009-06-03 Thread Moshe C.
Let's say I have a many to many relationship as for example in: orm.mapper(self.Person, person_table, properties = { 'relatives' : orm.relation(self.Person, secondary=person_relative_table, primaryjoin=person_table.c.id==person_relative_table.c.person_id,

[sqlalchemy] question regarding aliases in ORM, within an expression

2008-12-15 Thread Moshe C.
Table T has a self referential parent_id column. 'parent' is an orm.relation using that column. I have the following code which obviously does not work myquery = T.query() myquery = myquery.outerjoin('parent', aliased=True) myquery = myquery.reset_joinpoint() myquery =

[sqlalchemy] preventing aliases

2008-12-08 Thread Moshe C.
How can I prevent aliases fro appearing in the query? I have hit a MySQL bug that is related to a very biq SQL query string being sent and I am trying to shorten it. I might need an alias on one of the columns, though. The query is created originally by ORM query.compile() and then I create a

[sqlalchemy] ORM - Unmapping a class

2008-11-25 Thread Moshe C.
How would I unmap a class ( so that I can map it to another table from a parallel but distinct DB) ? I can't seem to find the documentation for the Mapper object itself. I may be going the wrong way about it. I want to map the same class to tables in different databases at different times.

[sqlalchemy] Re: ORM - Unmapping a class

2008-11-25 Thread Moshe C.
this correctly, I don't really need to touch the mappings at all since the tables remain the same, but just change the connection. I'll try it out. On Nov 25, 5:25 pm, Michael Bayer [EMAIL PROTECTED] wrote: Moshe C. wrote: How would I unmap a class ( so that I can map it to another table from a parallel

[sqlalchemy] How to rebind a ScopedSession?

2008-11-25 Thread Moshe C.
The ScopedSession class has no bind_table method. Is there a way to get at a Session object from ScopedSession object? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send

[sqlalchemy] confused about how functions work

2008-11-20 Thread Moshe C.
table.update(criterion, values={'last_edited' : func.now()} ).execute () works but table.update(criterion ).execute({'last_edited' : func.now()}) does not. It tries to set 'last_edited' to functions object. Can someone clarify the difference ?

[sqlalchemy] ORM Query that selects only a subset of the columns

2008-11-19 Thread Moshe C.
For Query there is an add_column() method, but I do not see a remove column method. Initializing a Query requires a full mapped class, so how can I select on only a subset of the columns. I want to do this for ding a DISTINCT query on only a couple of columns. TIA Moshe

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Moshe C.
0.4.6 On Nov 19, 11:12 pm, Bobby Impollonia [EMAIL PROTECTED] wrote: What version of SQLA are you using? In .5 , you can pass individual columns instead of a mapped class to session.query. On Wed, Nov 19, 2008 at 12:17 PM, Moshe C. [EMAIL PROTECTED] wrote: For Query there is an add_column

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Moshe C.
a look at the changelog to see what bugs have been fixed between 0.4.6 and 0.4.8. Moshe C. wrote: I have tried it out on 0.4.6 and it is working nicely. You mentioned 0.4.7 . Is there any bug I should be aware of  in 0.4.6? I cannot upgrade in the near future. On Nov 20, 12:19 am, Michael

[sqlalchemy] ORM: Retrieving table from mapped class

2008-11-16 Thread Moshe C.
Hi, Given a mapped ORM class, is it possible to retrieve from it the Table instabce to which it was mapped? TIA Moshe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send

[sqlalchemy] Re: ORM: Retrieving table from mapped class

2008-11-16 Thread Moshe C.
No, I am not using declarative . On Nov 17, 2:43 am, Bobby Impollonia [EMAIL PROTECTED] wrote: Are you using declarative? If so, your class will have a property called __table__ On Sun, Nov 16, 2008 at 4:04 PM, Moshe C. [EMAIL PROTECTED] wrote: Hi, Given a mapped ORM class

[sqlalchemy] Re: ORM: Retrieving table from mapped class

2008-11-16 Thread Moshe C.
thanks On Nov 17, 2:53 am, Michael Bayer [EMAIL PROTECTED] wrote: class_mapper(theclass).mapped_table On Nov 16, 2008, at 7:50 PM, Moshe C. wrote: No, I am not using declarative . On Nov 17, 2:43 am, Bobby Impollonia [EMAIL PROTECTED] wrote: Are you using declarative? If so, your

[sqlalchemy] avoiding locks with SA

2008-10-09 Thread Moshe C.
Let's say you have two concurrent processes where each might increment some integer field in some table row. If you query first and the increment in memory and then update, you need to query with_lockmode('update') to avoid the case where both processes read the same value and the do the same

[sqlalchemy] Temporarily disabling autoflush

2008-07-08 Thread Moshe C.
Hi, I have an autoflush session and I need it to be so. For one specific query though, I would like no flush to occur. How can I set an existing autoflush session to not autoflush and then reset it back to autoflush? TIA Moshe --~--~-~--~~~---~--~~ You received

[sqlalchemy] Re: How to union with orm, or maybe class inheritance?

2008-06-17 Thread Moshe C.
regarding union, maybe I am missing something basic. I use the session.query() with the orm stuff. How do I get the selects from those ? On Jun 17, 8:23 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Jun 17, 12:49 pm, Moshe C. [EMAIL PROTECTED] wrote: I have 3 tables: general_product {id

[sqlalchemy] Re: failure with correlate()

2008-05-27 Thread Moshe C.
? On May 27, 5:42 pm, Michael Bayer [EMAIL PROTECTED] wrote: On May 27, 2008, at 4:39 AM, Moshe C. wrote: I have the following mapping for classes One and Many: mapper(One, one_table, properties={'many':relation(Many)}) mapper(Many, many_table) and the following query

[sqlalchemy] order of execution with MapperExtension

2008-05-23 Thread Moshe C.
I have a mapper created with a mapper extension that has an after_update() override. For a table in the mapper I do an update and then a commit(). This is the resulting order of execution: update instance (setting an attribute on the mapped class) commit after_update called on instance I.e.

[sqlalchemy] Re: order of execution with MapperExtension

2008-05-23 Thread Moshe C.
PLEASE IGNORE PREVIOUS. It turns out that explicitly flushing does change the order (made a silly coding error before). I am all set, but the question remains why autoflush isn't enough. On May 23, 2:15 pm, Moshe C. [EMAIL PROTECTED] wrote: I have a mapper created with a mapper extension

[sqlalchemy] Re: order of execution with MapperExtension

2008-05-23 Thread Moshe C.
I traced what is happening in the code. I don't fully understand it but I hope the following will help. The crucial point is that in my after_update() method I create a mapped object and call session.save() using the same session (but different table). This is the sequence of events: - I call

[sqlalchemy] Re: order of execution with MapperExtension

2008-05-23 Thread Moshe C.
[EMAIL PROTECTED] wrote: On May 23, 2008, at 6:54 PM, Moshe C. wrote: I traced what is happening in the code. I don't fully understand it but I hope the following will help. The crucial point is that in my after_update() method I create a mapped object and call session.save() using the same

[sqlalchemy] 0.3 -- 0.4 : dictionaries for execute()

2008-05-21 Thread Moshe C.
This is probably very simple, but I am searching the docs and not finding the answer :-( In 0.3 I had a working statement of the form: engine.execute(table.select(), cond_dict) where cond_dict is a dictionary of column names mapped to values. In 0.4.6 this does not work. What is produced in SQL

[sqlalchemy] Re: 0.3 -- 0.4 : dictionaries for execute()

2008-05-21 Thread Moshe C.
Thanks. So I guess you cannot use the dictionary argument as is. It was very convenient. On May 21, 6:16 pm, Michael Bayer [EMAIL PROTECTED] wrote: On May 21, 2008, at 11:06 AM, Moshe C. wrote: This is probably very simple, but I am searching the docs and not finding the answer

[sqlalchemy] Re: retrieving mapped objects from within a session

2008-05-18 Thread Moshe C.
Got back to this issue after a while. The SessionExtension objects allows me to hook on to a session and get notified of various events. My question is different: Given a session, before commit, how can I query it to know what is going to happen at commit. My intention is to derive from that, a

[sqlalchemy] Ordering results ina self-referential join

2008-05-06 Thread Moshe C.
Hi, Node is an orm mapped class, which is self-referential. myquery = Node.query() myquery = myquery.join('parent', aliased=True) myquery = myquery.filter(Node.c.desc.like('%something')) myquery = myquery.order_by(Node.c.name) The last line orders by the 'name' of the 2nd joined table. How

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Moshe C.
._order_by + criterion TypeError: can only concatenate list (not tuple) to list On May 6, 8:45 pm, Michael Bayer [EMAIL PROTECTED] wrote: On May 6, 2008, at 1:43 PM, Moshe C. wrote: Hi, Node is an orm mapped class, which is self-referential. myquery = Node.query() myquery

[sqlalchemy] Re: Ordering results ina self-referential join

2008-05-06 Thread Moshe C.
= myquery.reset_joinpoint().order_by(Node.c.popularity) # _aliases_tail is None for this call On May 6, 10:25 pm, Michael Bayer [EMAIL PROTECTED] wrote: On May 6, 2008, at 3:08 PM, Moshe C. wrote: Both methods cause a crash (yes, on 0.4.5) . converting a tuple to a list in sqlalchemy

[sqlalchemy] retrieving mapped objects from within a session

2008-04-06 Thread Moshe C.
Is it possible to retrieve mapped objects from a session. The motivation: I want to maintain history log tables where a row is added per each update or insert on the corresponding main table. The schema of the tables is identical except for an additional timestamp in the history table. I want

[sqlalchemy] insert of a sequence of dictionaries

2007-09-03 Thread Moshe C.
The following line: r = cnnctn.execute(insert(t), {'xkey': 'k1','yval':1}, {'xkey': 'k2','yval':2}, {'xkey': 'k3'}) Cause the following : INSERT INTO `A` (xkey, yval) VALUES (%s, %s) [['k1', 1], ['k2', 2], ['k3', 1]] i.e. the unspecified value in the

[sqlalchemy] Re: outerjoin constructor throws exception from 0.3.9. Bug or user error?

2007-08-30 Thread Moshe C.
Raising this after 3 days, still hoping for help :-) --~--~-~--~~~---~--~~ 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

[sqlalchemy] Re: Testing for validity of a Connection

2007-08-30 Thread Moshe C.
('select 1') On 8/30/07, Moshe C. [EMAIL PROTECTED] wrote: How can I test whether a connection object is valid and hasn't, for example, been time outed by the server? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups