[sqlalchemy] Making ResultProxy test as False when there are no rows
Would it make sense to add a __nonzero__ method to ResultProxy that was tied to the rowcount? def __nonzero__(self): return bool(self.rowcount) This would allow code like if results: process(results) I was surprised when this did not work. -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] passing parameters to subquery in mapped select
On Oct 14, 2011, at 10:56 AM, Burak Arslan wrote: On 10/14/11 06:40, Michael Bayer wrote: its a little awkward but if you use bindparam() in the inner select, query.params() can access those parameters just fine, you'd just need to use it in all cases. there's some related example of doing this with a relationship at http://www.sqlalchemy.org/trac/wiki/UsageRecipes/GlobalFilter . hi michael, thank you very much for the reply, your suggestion solves my issue. however, I do agree that it's a little bit awkward to have to remember a params() after a .filter(), is there any reason for not unifying them? how would a unification of filter() and params() look ? filter() expresses expression structures, and params() the values. You can use just filter() with literal values and they are converted into bind params automatically. just not clear what you mean here. -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Making ResultProxy test as False when there are no rows
On Oct 14, 2011, at 10:38 AM, Lloyd Kvam wrote: Would it make sense to add a __nonzero__ method to ResultProxy that was tied to the rowcount? def __nonzero__(self): return bool(self.rowcount) This would allow code like if results: process(results) I was surprised when this did not work. this is because .rowcount is not related to the count of rows in a result set. Some DBAPI's may do this, but this is not the intent of .rowcount and is not supported on most. .rowcount is only intended to describe the number of rows matched by an UPDATE or DELETE statement. The only way to know if there are any rows in a result set are to fetch them. The cursor itself, based on backend, doesn't even know there's a row until it sends a message to the database to get the first row. Therefore you have to use fetchone() to check for a row. -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] passing parameters to subquery in mapped select
On 10/14/11 18:01, Michael Bayer wrote: On Oct 14, 2011, at 10:56 AM, Burak Arslan wrote: On 10/14/11 06:40, Michael Bayer wrote: its a little awkward but if you use bindparam() in the inner select, query.params() can access those parameters just fine, you'd just need to use it in all cases. there's some related example of doing this with a relationship at http://www.sqlalchemy.org/trac/wiki/UsageRecipes/GlobalFilter . hi michael, thank you very much for the reply, your suggestion solves my issue. however, I do agree that it's a little bit awkward to have to remember a params() after a .filter(), is there any reason for not unifying them? how would a unification of filter() and params() look ? filter() expresses expression structures, and params() the values. You can use just filter() with literal values and they are converted into bind params automatically. just not clear what you mean here. I mean, currently my query looks like this: query(SomeTable).filter_by(some_column=some_val).params(some_other_col=some_other_val) I'd prefer: query(SomeTable).filter_by(some_column=some_val, some_other_col=some_other_val) that's not much of a hassle to be honest, but i'm just curious. thanks, burak -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Making ResultProxy test as False when there are no rows
On Oct 14, 11:02 am, Michael Bayer mike...@zzzcomputing.com wrote: On Oct 14, 2011, at 10:38 AM, Lloyd Kvam wrote: Would it make sense to add a __nonzero__ method to ResultProxy that was tied to the rowcount? def __nonzero__(self): return bool(self.rowcount) This would allow code like if results: process(results) I was surprised when this did not work. this is because .rowcount is not related to the count of rows in a result set. Some DBAPI's may do this, but this is not the intent of .rowcount and is not supported on most. .rowcount is only intended to describe the number of rows matched by an UPDATE or DELETE statement. The only way to know if there are any rows in a result set are to fetch them. The cursor itself, based on backend, doesn't even know there's a row until it sends a message to the database to get the first row. Therefore you have to use fetchone() to check for a row. I apologize for not reading the documentation. http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engine.base.ResultProxy.rowcount Thanks for being so kind in setting me straight. -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] can't find a way to index field with orm.
Hello all, I feel I am seriously missing some point here. suppose I am creating a class representing a table through orm. I will asume that it is using declarative syntax. I wish to know how do we index a field? that is to say, I need to have indexes on a few fields so that they are applied to the tables in my postgresql database. I know how to use primary key but wish to know if I can add indexes to the fields. Happy hacking. Krishnakant. -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] IS DISTINCT FROM
What is the SA equivalent of: UPDATE foo SET bar=some_function(baz) WHERE bar IS DISTINCT FROM some_function(baz) I get this far (assuming 't' is a Table instance): t.update().values(t.c.bar=sa.func.some_function(t.c.baz).where( ... what do I put here ) IS DISTINCT FROM (and IS NOT DISTINCT FROM) are supported in firebird and postgresql, and possibly others. -- Jon -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: IS DISTINCT FROM
On Fri, Oct 14, 2011 at 4:45 PM, Jon Nelson jnel...@jamponi.net wrote: What is the SA equivalent of: UPDATE foo SET bar=some_function(baz) WHERE bar IS DISTINCT FROM some_function(baz) I get this far (assuming 't' is a Table instance): t.update().values(t.c.bar=sa.func.some_function(t.c.baz).where( ... what do I put here ) IS DISTINCT FROM (and IS NOT DISTINCT FROM) are supported in firebird and postgresql, and possibly others. Is using 'op' the right way? c = sa.func.some_function(t.c.baz) t.update().values(t.c.bar=c).where(t.c.bar.op(IS DISTINCT FROM)(c)) -- Jon -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: IS DISTINCT FROM
for now yes, I've not heard of IS DISTINCT FROM before. On Oct 14, 2011, at 6:25 PM, Jon Nelson wrote: On Fri, Oct 14, 2011 at 4:45 PM, Jon Nelson jnel...@jamponi.net wrote: What is the SA equivalent of: UPDATE foo SET bar=some_function(baz) WHERE bar IS DISTINCT FROM some_function(baz) I get this far (assuming 't' is a Table instance): t.update().values(t.c.bar=sa.func.some_function(t.c.baz).where( ... what do I put here ) IS DISTINCT FROM (and IS NOT DISTINCT FROM) are supported in firebird and postgresql, and possibly others. Is using 'op' the right way? c = sa.func.some_function(t.c.baz) t.update().values(t.c.bar=c).where(t.c.bar.op(IS DISTINCT FROM)(c)) -- Jon -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: IS DISTINCT FROM
On Fri, Oct 14, 2011 at 8:12 PM, Michael Bayer mike...@zzzcomputing.com wrote: for now yes, I've not heard of IS DISTINCT FROM before. In the right places, it's mighty useful. -- Jon -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Degenerate relationship?
There are two tables pump and curve. The curve table has three fields, curve_pn, head and gpm. The design is that the rows with the same curve_pn value represent x,y points (head,gpm) on a pump performance curve. Each row in the pump table has a curve_pn column that links to the performance curve for that pump. The same performance curve can apply to multiple pumps. To me it seems that there is a many-many relationship, yet there is no association table. This design works fine in straight SQL. To model it in SQLAlchemy, do I need to add an association table? For the purposes of this application, the data is read-only, but if it were not, if the data for a curve were to change, I would want it to change for all the pumps that use that curve_pn. TIA, Mark -- 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 group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.