Thank you Michael for your explanation. Since I can do (on sqlalchemy), the same thing in more than one ways, I'm very confused and I would like ask you, about Constructing SQL Queries via _table objects_ or _mapper classes_
Seems to me that *table object* is more flexible than *classe*s to construct a query, but I wonder what the difference between those and when/why using one or another... c = select(users) c = session.query(Users) jo Michael Bayer wrote: >oh, in all cases it is perfectly acceptable to write the queries as >text, of course...usually when someone asks me "how do i write query >X", i assume they are looking for the "constructed" version of >it....since they already wrote the non-constructed version. > >areas where "constructed" queries are better: > >1. the ORM needs to know the list of columns from a constructed SQL >statement as well as the underlying tables used in the statement; so >constructed statements are usually required if youre going to map with >them using the ORM. >2. anytime you have an application that is programmatically building up >or modifying a query, constructed is better, since you easily can add >syntactic elements without needing to parse/modify string SQL text >3. the constructed syntax is more succinct in many cases - i.e. >table.insert().execute(x=5), table.select(table.c.y==7), etc. >4. you get the database-agnostic behavior. there are advantages here >with regards to inserts (abstracts away primary key generation), in >some cases joins (oracle 8 requires the (+) operator for outer joins), >quoting rules (reserved words, mixed case identifiers automatically >quoted as per the database's quoting rules), and a variety of little >things, like column==None becomes "column IS NULL", etc. >5. all of the WHERE criterion you send to an ORM query needs to be >constructed so that eager loads and such can build up their own >criterion and modifications on top of the central query. > > >> > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
