[sqlalchemy] Re: SqlSoup joins broken in 0.5.3

2009-03-31 Thread Jonathan Ellis
You can't just throw filter expressions into the join call in modern sqla. Try db.devmap_device.join(db.devmap_manufacturer).filter(db.devmap_device.manufacturer_id == db.devmap_manufacturer.id).first() -Jonathan On Tue, Mar 31, 2009 at 8:23 AM, Stu.Axon stu.a...@gmail.com wrote: Heres some

[sqlalchemy] time to remove create_session?

2008-06-27 Thread Jonathan Ellis
I replaced create_session in sqlsoup with scoped_session, which appears to have been the only reference to it. -Jonathan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send

[sqlalchemy] Re: has() and multiple tables

2008-04-08 Thread Jonathan Ellis
On 4/7/08, Jonathan Ellis [EMAIL PROTECTED] wrote: I'm confused -- this sample does correlate actions with tasks, but not tasks with connections. Intuitively it seems that X.has(Y) should always add a clause to the the exists for y.y_id = x.y_id. No? Mike cleared this up for me in IRC

[sqlalchemy] Re: has() and multiple tables

2008-04-08 Thread Jonathan Ellis
On 4/8/08, Tim Lesher [EMAIL PROTECTED] wrote: Yep--that's what I'm doing now. It has the effect of creating another nested subselect, but I'm not too concerned about that as both are relatively cheap EXISTS queries. I wouldn't be surprised if PG's optimizer can inline it anyway.

[sqlalchemy] Re: has() and multiple tables

2008-04-07 Thread Jonathan Ellis
On 4/7/08, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 7, 2008, at 4:54 PM, Tim Lesher wrote: session .query(Action).filter(Action.task.has(Connection.caller==caller1)) for this kind of thing, you're joining across three tables, so you can put an extra join condition in the has():

[sqlalchemy] SQLAlchemy advanced tutorial at PyCon

2008-01-28 Thread Jonathan Ellis
Hi all, Michael and I will be presenting beginning and advanced SQLAlchemy tutorials at PyCon in March. The beginning session will cover similar ground to my OSCON tutorial last year: http://spyced.blogspot.com/2007/07/final-version-of-oscon-sqlalchemy.html What would you like to see covered

[sqlalchemy] Re: Implementing ranking

2007-12-23 Thread Jonathan Ellis
On 12/19/07, voltron [EMAIL PROTECTED] wrote: Could someone tell me how to simulate the rank() function? I am using PostgreSQL which does not have this a s a native function. SA doesn't give any special support for this. You'll have to rewrite your query. For example,

[sqlalchemy] Re: SQLAlchemy 0.4 beta2 released

2007-08-14 Thread Jonathan Ellis
On 8/14/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: im not sure try/except is faster here - im pretty sure a missing key is likely and exception throws are very expensive. would be worth a try to see if the missing key exception actually occurs here. i'll have to check, last 3 years

[sqlalchemy] Re: Using a non-string in sqlalchemy

2007-08-06 Thread Jonathan Ellis
On 8/6/07, malkarouri [EMAIL PROTECTED] wrote: rec = Record() setattr(rec, col, val) This works if col is a string (the column subclassing SQLAlchemy's String) but not otherwise. I can identify the type of the column as I think most people just use a higher-level forms api. -Jonathan

[sqlalchemy] Re: right outer join (newbie)

2007-08-02 Thread Jonathan Ellis
There are good reasons to support full outer join. Some are suggested in the comments to that one article. :) I don't miss right joins though, I find left join more natural. On 8/1/07, Michael Bayer [EMAIL PROTECTED] wrote: we currently dont have a right outer join. but this is not by

[sqlalchemy] Re: SQLAlchemy 0.4 MERGED TO TRUNK

2007-07-30 Thread Jonathan Ellis
I can probably do this tonight. How many people are still using 2.3? Decorator syntax would be nice for this. Also it would be nice to not have to remember that I can't use genexps in SA code. But 2.3 is a pretty good base, I don't miss much else from 2.4. :) On 7/30/07, Michael Bayer [EMAIL

[sqlalchemy] Re: SQLAlchemy 0.4 MERGED TO TRUNK

2007-07-27 Thread Jonathan Ellis
I'd want to make sure this didn't hurt performance first. (Seems innocuous enough, but if it's in any sort of inner loop the extra hash lookup might be noticeable.) On 7/27/07, svilen [EMAIL PROTECTED] wrote: one suggesstion / request. As your changing everything anyway, can u replace all

[sqlalchemy] Re: no RowProxy.__getslice__

2007-07-25 Thread Jonathan Ellis
Well, the docs you link say slicing should be done via __getitem__ now. Which is also present in dicts of course. Why not approach the problem from the other direction? try: maybedict.keys() except AttributeError: ismapping = True else: ismapping = False ? On 7/25/07, Catherine [EMAIL

[sqlalchemy] Re: Model to Dictionary

2007-07-25 Thread Jonathan Ellis
why not just pass model_instance.__dict__ ? On 7/23/07, HiTekElvis [EMAIL PROTECTED] wrote: Anybody know a way to change a model into a dictionary? For those to whom it means anything, I'm hoping to pass that dictionary into a formencode.Schema.from_python method. Any ideas? -Josh

[sqlalchemy] Re: Insert through ORM performance (was: Performance question)

2007-07-22 Thread Jonathan Ellis
On 7/19/07, Mike Orr [EMAIL PROTECTED] wrote: I'm amazed at the speed of mysqldump and its reloading. It packs a bunch of rows into one INSERT statement. I don't see why that's so much faster than than executemany but it provides another potential avenue for speed. I'm not sure if MySQL is

[sqlalchemy] Re: multiple mappers on une table problem.

2007-06-19 Thread Jonathan Ellis
On 6/11/07, Michael Bayer [EMAIL PROTECTED] wrote: secondly: a non-primary mapper is just an awkward way of defining an ORM query. Since we support generative queries now, you can just make a Query object with the criterion youre looking for and just hold onto it...youre just adding a single

[sqlalchemy] Re: PROPOSAL: whack query.select(), selectfirst(), selectone(), select_by(), selectfirst_by(), selectone_by(), get_by(), auto-join feature

2007-06-12 Thread Jonathan Ellis
Cleaning out my inbox... FWIW I'm +1 on removing the old-style methods, +1 on .first instead of .scalar, +1 on adding .one, and +0 on renaming .list to .all. Did you make a decision for 0.4 Mike? -J --~--~-~--~~~---~--~~ You received this message because you

[sqlalchemy] SQLAlchemy at OSCON

2007-04-27 Thread Jonathan Ellis
As I understand it, the schedule is still tentative at this point, but the fact that I'll get to teach a SQLAlchemy tutorial is not. (Like my PyCon tutorial, this will be aimed at those who have not yet used SA.) O'Reilly Open Source Convention 2007 at the Oregon Convention Center in Portland,

[sqlalchemy] Re: Connection handling, re-establishing connections?

2007-03-29 Thread Jonathan Ellis
On 3/25/07, Michael Bayer [EMAIL PROTECTED] wrote: Still, all of these measures require that we actually get an error thrown to detect that a restart took place, which inconveniently usually happens not at the point of cursor() but at the point of execute(), and we dont have any frameworks in

[sqlalchemy] Re: What should the future of SQLAlchemy Query look like ?

2007-03-08 Thread Jonathan Ellis
On 3/8/07, Michael Bayer [EMAIL PROTECTED] wrote: hey list - I continue to be troubled by the slightly fragmented nature of SA's Query object (and the cousin SelectResults). When I work with Hibernate, I can see that their querying interface is a little more consistent than ours. We have

[sqlalchemy] Re: What should the future of SQLAlchemy Query look like ?

2007-03-08 Thread Jonathan Ellis
On 3/8/07, Michael Bayer [EMAIL PROTECTED] wrote: how often do you have a base query hanging around, vs. doing brand new query object each time? with the full generative way, if you are programatically building up your query, now you have to say: if somecriterion: q =

[sqlalchemy] Re: sa newbie

2007-03-06 Thread Jonathan Ellis
try db.books.select(db.books.c.book_skus.like('abcd%')) On 3/5/07, dan [EMAIL PROTECTED] wrote: I'm trying to track down the syntax for using a 'like' clause with sql soup. I'm trying to do something like select book_sku from books where book_sku like 'abcd%'; best i can tell, my

[sqlalchemy] Re: How to do aggregates with mapped entity objects?

2007-02-27 Thread Jonathan Ellis
You don't, it doesn't work that way. You can map the aggregate as a (SA) property of another class, or make it a (Python) property/function of the Expense class. Either way you'll have to create a select object, either for the mapping or a manual query. On 2/27/07, Pradeep [EMAIL PROTECTED]

[sqlalchemy] Re: Auto-joins via FK

2007-02-27 Thread Jonathan Ellis
On 2/27/07, Rick Morrison [EMAIL PROTECTED] wrote: Shouldn't SA be able to figure out the following joins without needing the explicit join params? no, SA never tries to guess how you want to join things because then you'd have to add a way to override it when it guesses wrong and it's simpler

[sqlalchemy] Re: how to get column names in result

2007-02-26 Thread Jonathan Ellis
You can see what columns are part of a table (or a select!) with .columns.keys() or .c.keys(). On 2/24/07, vkuznet [EMAIL PROTECTED] wrote: Hi, a very simple question which I cannot find in documentation. How to get column names together with result. This is useful for web presentation of

[sqlalchemy] Re: Complicated Mapper with Count Function

2007-02-26 Thread Jonathan Ellis
you need to use an outer join (or a subselect) to get a row to come back even when there is no match in the right table. adding from_obj=[outerjoin(product_table, stock_product_table)] to what you have now would probably work. (personally i think a subselect would be better style here but i

[sqlalchemy] Re: how to force a clean refresh of a lazy loaded attribute

2007-02-26 Thread Jonathan Ellis
you could certainly write a helper function if you find that you do this a lot. I'd be -1 on making it official, it just seems messy to me. (defining collection only as list is sucky; defining collection as anything you can iterate over is problematic because an instance that is itself in the

[sqlalchemy] Re: select ... having problems

2007-02-24 Thread Jonathan Ellis
Something like this should work: select(['count(distinct flow.node_id) as nodes', ip], from_obj=[flow.join(id)], group_by=[flow.c.src_id], having=['nodes 5'], order_by=[desc('nodes')]) If you wanted to do it w/o text blocks I think you'd have to create a subselect first to pull the nodes

[sqlalchemy] Suggestion to support full outer joins

2007-02-20 Thread Jonathan Ellis
Instead of isouter argument to Join, have join_type. Default to 'inner' but could also be 'left', 'right', or 'outer.' (Or even 'natural' but that might be confusing b/c of Join's default behavior of joining by FK which is similar to but not the same as natural join.) (Of course, it's quite

[sqlalchemy] Re: Suggestion to support full outer joins

2007-02-20 Thread Jonathan Ellis
On 2/20/07, Jonathan Ellis [EMAIL PROTECTED] wrote: Instead of isouter argument to Join, have join_type. Default to 'inner' but could also be 'left', 'right', or 'outer.' should read ... or 'full,' of course. --~--~-~--~~~---~--~~ You received this message

[sqlalchemy] Re: SA skips integrity referential?

2007-02-16 Thread Jonathan Ellis
On 2/16/07, jose [EMAIL PROTECTED] wrote: Gary Bernhardt wrote: Referential integrity isn't being violated here - SA is nulling the foreign key before deleting the row it points to. Try adding nullable=False to the declaration of attivita.cod_specie. That should make it fail in the

[sqlalchemy] Re: postgres, autoload, and odd datatypes

2007-02-16 Thread Jonathan Ellis
I'd prefer to not have them loaded at all (maybe with log.warning) than to have them loaded with a known-to-be-incorrect type. If you really don't want to manipulate them from Python, not loading them is the Right Thing. If you do want to manipulate them then the Right Thing is to add the

[sqlalchemy] Re: Reflection including Relations

2007-02-16 Thread Jonathan Ellis
You say defined manually... automatically. It can't be both. :) SA won't try to guess what properties you want on your mapped classes, because it could guess wrong. (Believe me, whatever pattern you are thinking of, someone could find an exception where automatically setting it up is not the

[sqlalchemy] Re: SA skips integrity referential?

2007-02-16 Thread Jonathan Ellis
On 2/16/07, jose [EMAIL PROTECTED] wrote: Jonathan Ellis wrote: Guess it would surprise you to learn about the SQL 92 ON DELETE SET NULL functionality too. :) Seems to me the SQL92 'ON DELETE SET NULL' is an explicit functionality, instead in our case, SA does this functionality

[sqlalchemy] Re: SA skips integrity referential?

2007-02-16 Thread Jonathan Ellis
] wrote: Jonathan Ellis wrote: On 2/16/07, jose [EMAIL PROTECTED] wrote: Jonathan Ellis wrote: Guess it would surprise you to learn about the SQL 92 ON DELETE SET NULL functionality too. :) Seems to me the SQL92 'ON DELETE SET NULL' is an explicit functionality, instead

[sqlalchemy] Re: Announcing Elixir!

2007-02-15 Thread Jonathan Ellis
LaCour [EMAIL PROTECTED] wrote: Jonathan Ellis wrote: Is there a what's new and improved in Elixir document anywhere? Well, its pretty much entirely new and improved over TurboEntity and ActiveMapper, in that it provides a totally different way of doing things. The extensive documentation

[sqlalchemy] Re: how do I set an engine to autocommit?

2007-02-01 Thread Jonathan Ellis
On 2/1/07, Kumar McMillan [EMAIL PROTECTED] wrote: the fact that the deadlock was solved when I added the connection to the transaction tells me that psycopg runs in commit mode automatically (even though dbapi 2 says it should not). The psycopg docs reinforce this too :

[sqlalchemy] pool echo

2007-01-25 Thread Jonathan Ellis
Minor question: wouldn't it be more consistent to either apply echo to all pool logging, or get rid of it and let logger settings control it? Here's a patch for the former. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google

[sqlalchemy] Re: any particular reason for creating unused lists?

2007-01-25 Thread Jonathan Ellis
Reasonable people can differ here, but I agree that if what you care about is a side effect, rather than a resulting list, using a for loop is more clear than a list comprehension. (I suspect it is also more performant since you are not allocating and populating a list object for no reason.)

[sqlalchemy] Re: is pool supposed to be able to handle its target db restarting?

2007-01-25 Thread Jonathan Ellis
are getting, the connections should all be getting returned above ( or some exception would be thrown). are you stopping the DB while the first fetchall() is executing ? or in between ? On Jan 25, 3:54 pm, Jonathan Ellis [EMAIL PROTECTED] wrote: from sqlalchemy import * e = create_engine

[sqlalchemy] Re: SQLite, append_column?

2007-01-23 Thread Jonathan Ellis
SA doesn't support doing ADD COLUMN or almost any other ALTER command. If you ran the ALTER manually then created a new Table with autoload it would of course load the new version, but I'm at a loss to see why you'd need that. On 1/23/07, Basil Shubin [EMAIL PROTECTED] wrote: So, there is no

[sqlalchemy] Re: Extracting date parts from datetime with postgresql

2007-01-22 Thread Jonathan Ellis
date_part is a synonym for extract w/ more normal syntax so you could write func.date_part('year', mydatetime) On 1/22/07, laurent rahuel [EMAIL PROTECTED] wrote: Hi, Here is my little trouble. I want to extract some parts of a datetime field in a postgresql database. I played around

[sqlalchemy] Re: transactions

2007-01-20 Thread Jonathan Ellis
yes, you should, and your commented-out code looks fine On 1/20/07, jose [EMAIL PROTECTED] wrote: Hi all, I have a question about transactions I need to insert data into two tables (anag and user), sice I need to insert the generated primary key of anag into user. I have to flush anag

[sqlalchemy] Re: Simple transactions

2007-01-18 Thread Jonathan Ellis
On 1/17/07, Miki [EMAIL PROTECTED] wrote: # Notice we didn't commit yet This means that if someone is querying the table in the middle of the transaction it'll get wrong results. (I'm not a DB expert, this might be total nonsense) no, it just means that queries run in the same uncommitted

[sqlalchemy] Re: Accessing DBAPI cursor object from connection

2007-01-18 Thread Jonathan Ellis
engine.raw_connection().cursor() On 1/18/07, Sean Davis [EMAIL PROTECTED] wrote: I would like to access the underlying psycopg2 connection to get at a DBAPI2 cursor with the ultimate goal of using the copy_from/copy_to protocol for moving large amounts of data to/from the database. I can't

[sqlalchemy] Re: Postgre e pg_largeobject

2007-01-17 Thread Jonathan Ellis
On 1/17/07, Antonio [EMAIL PROTECTED] wrote: and now, how can I retrieve the file (res.pdf.data) in a file or send it as output in a html page (sendig the right headers) ? Nothing magical: file('foo.pdf', 'wb').write(res.pdf.data) see your html framework's docs for instructions on sending

[sqlalchemy] Re: Postgre e pg_largeobject

2007-01-17 Thread Jonathan Ellis
Oops, I didn't notice at first that you are using pg_largeobject... That's not a good idea, you should really use bytea (for SA, that means declaring filepdf as a Binary column itself rather than linking to pg_largeobject) unless you are planning to manually seek inside the lo (i.e. with

[sqlalchemy] Re: Profiling mode

2007-01-17 Thread Jonathan Ellis
, Jonathan Ellis wrote: For me it has been useful in the past to track overall database query speed so I could optimize the query taking the most aggregate time. (I.e., execution time * times executed.) It looks to me like this could be hooked in to SA pretty easily, with just a minor change

[sqlalchemy] Re: Profiling mode

2007-01-17 Thread Jonathan Ellis
Thinking about it more, I should probably just override the methods of Connection itself and not worry about subclasses. If someone is overriding _execute*, he can do his own damn profiling. :) On 1/17/07, Jonathan Ellis [EMAIL PROTECTED] wrote: I finally came back to this. Here's what I

[sqlalchemy] Re: adding a foreign key constraint to an existing table

2007-01-15 Thread Jonathan Ellis
On 1/15/07, Michael Bayer [EMAIL PROTECTED] wrote: 2. no support for CASCADE in the DROP statement right now. someone fill me in, is DROP CASCADE part of the sql standard ? yes, at least for tables. --~--~-~--~~~---~--~~ You received this message because you

[sqlalchemy] Re: How to query like sys_id=42 AND ts_created 90 minutes ago ?

2007-01-12 Thread Jonathan Ellis
You can shorten it a little by having the db do the date operation: History.c.ts_created func.now() - '90 minutes' On 1/11/07, Chris Shenton [EMAIL PROTECTED] wrote: I've got a bunch of history and other timestamped information I will need to query against. The columns are created with type

[sqlalchemy] Re: Mapping special child rows

2007-01-12 Thread Jonathan Ellis
Okay, I have another question related to this. Now that I have max_order defined, I want to do a query on it (give me the users whose max_order==5). My code is max_orders_by_user = select([func.max(orders.c.order_id).label('order_id')], group_by=[orders.c.user_id]).alias('max_orders_by_user')

[sqlalchemy] Re: Composite primary key

2007-01-09 Thread Jonathan Ellis
Well, you could specify the primaryjoin as described here: http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_properties_customjoin but I suspect that your existing mapper will Just Work if you switch to a composite FK, rather than 3 keys on individual columns t_bovines = Table(

[sqlalchemy] Re: customize table creation

2007-01-09 Thread Jonathan Ellis
On 1/9/07, Daniel Haus [EMAIL PROTECTED] wrote: Hi alchemists! Is there any way to have SA do some custom work before it creates a table? I tried to subclass Table and override create, which obviously doesn't work that easily. Any suggestions or ideas? The background is, I have some

[sqlalchemy] Mapping special child rows

2007-01-07 Thread Jonathan Ellis
Say I have tables corresponding to users and orders from test/tables.py. I have dozens or hundreds of orders per user. I want to show a list of users with their most recent order, but because I have so many orders doing an eager load to orders is a bad solution. Having a manually defined

[sqlalchemy] Re: How to order by a field in a different table?

2007-01-06 Thread Jonathan Ellis
A query that doesn't rely on broken GROUP BY might look like select([forum_topics, select([func.max(forum_posts.c.created)], forum_posts.c.topic_id==forum_topics.c.id, scalar=True).label('last_post')], order_by=[desc('last_post')]) On 12/28/06, Mart

[sqlalchemy] Re: remote nondirect access to DB

2006-12-08 Thread Jonathan Ellis
On 12/8/06, ml [EMAIL PROTECTED] wrote: Jonathan Ellis píše v Pá 08. 12. 2006 v 11:05 -0700: On 12/7/06, ml [EMAIL PROTECTED] wrote: I want to have a client application accessing a remote Postgres database but I don't want to distribute the user/password to the DB. I want clients

[sqlalchemy] Re: Proposal: session identity_map no longer weak referencing

2006-12-08 Thread Jonathan Ellis
stays there until you clean it out. that behavior is more predictable than what we have now. +1 Of course we can always add an option weak_identity_map if people really do want the old behavior. -1, it's only a matter of time before this would bite you -- Jonathan Ellis http

[sqlalchemy] Re: sqlalchemy limiting

2006-12-05 Thread Jonathan Ellis
http://www.sqlalchemy.org/docs/plugins.myt#plugins_selectresults On 12/5/06, dischdennis [EMAIL PROTECTED] wrote: What exactly is the SelectResults extension and where can I get it? -- Jonathan Ellis http://spyced.blogspot.com --~--~-~--~~~---~--~~ You

[sqlalchemy] Re: columns inheritance

2006-12-05 Thread Jonathan Ellis
heirarchies), I think this is as good as you're going to get. -- Jonathan Ellis http://spyced.blogspot.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email

[sqlalchemy] SQLAlchemy at pycon 07

2006-11-29 Thread Jonathan Ellis
My proposal for a talk on SqlSoup was accepted. It looks like someone else's talk on SA itself was accepted too. Woot! :) -- Jonathan Ellis http://spyced.blogspot.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google

[sqlalchemy] Re: SQLAlchemy at pycon 07

2006-11-29 Thread Jonathan Ellis
Right now you can only see the status of proposals you submitted yourself, but the final schedule is probably only a couple days away from being announced. On 11/29/06, Karl Guertin [EMAIL PROTECTED] wrote: On 11/29/06, Jonathan Ellis [EMAIL PROTECTED] wrote: My proposal for a talk

[sqlalchemy] Re: Clases with __slots__ attribute

2006-11-09 Thread Jonathan Ellis
.) -- Jonathan Ellis http://spyced.blogspot.com --~--~-~--~~~---~--~~ 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

[sqlalchemy] Select statement should not be in its own _froms list

2006-10-30 Thread Jonathan Ellis
(object): pass mapper = mapper(YearWithCount, s) session = create_session() q = session.query(YearWithCount) q.select_by(published_year='2006') # sqlalchemy.exceptions.AssertionError: Select statement should not be in its own _froms list -- Jonathan Ellis http://spyced.blogspot.com

[sqlalchemy] Profiling mode

2006-10-30 Thread Jonathan Ellis
other code paths that would have to be tracked? -- Jonathan Ellis http://spyced.blogspot.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy

[sqlalchemy] Re: Select statement should not be in its own _froms list

2006-10-30 Thread Jonathan Ellis
=[b], group_by=[b.c.published_year]) i guess you already knew that. On Oct 30, 2006, at 6:19 PM, Jonathan Ellis wrote: from sqlalchemy import * e = create_engine('sqlite:///:memory:', echo=True) md = BoundMetaData(e) sql = CREATE TABLE books ( id integer