[sqlalchemy] problem with mapped object in different database.

2008-09-26 Thread Mike Bernson
I have a number of database that have the same tables in them. I create a session for 1 data and do some work. This work causes a number of table table object to be reflected from the database and then mapped. This works fine. Now I Switch to another database which has the same tables. If I acce

[sqlalchemy] reflection unavailable for mysql temporary tables?

2008-09-26 Thread Andy Davidoff
Reflection of temporary tables under MySQL works around revision 4000 and probably as recently as May but doesn't seem to work under revision 5000 or later; I get a NoSuchTableError. Is this change intentional? If the only change I make to my code is to create and reflect a normal table versus a

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Doug Farrell
Michael, After some tweaking around, it works! Thanks for all your help, it was invaluable! I'm sure I'll be back for more though... J Doug From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Michael Bayer Sent: Friday, September 26, 2008 5:50 PM To: sqlalchemy@googl

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 5:42 PM, Doug Farrell wrote: > I’m have the ‘type’ column in the press_routing_press linking table; > something like this: > > Sess.query(Press, > PressRoutingPress > .type).join(Press.routes).filter(PressRouting.code==’A’).all() > > I’ve tried some variations of this, bu

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Doug Farrell
I'm have the 'type' column in the press_routing_press linking table; something like this: Sess.query(Press, PressRoutingPress.type).join(Press.routes).filter(PressRouting.code=='A' ).all() I've tried some variations of this, but no luck. I've also tried applying what the documentation says

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Michael Bayer
sess.query(Press, PressRouting .code).join(Press.routes).filter(PressRouting.code=='A').all() will return tuples in the form: (some Press object, "somecode") On Sep 26, 2008, at 3:25 PM, Doug Farrell wrote: > Michael, > > You’re right of course, your version works fine. I cut and pasted

[sqlalchemy] Re: Comparable Property in partial selects

2008-09-26 Thread Alex K
Sorry, I've re-checked, it was my typo, all properties co-exist ok, Thanks again, Alex On 26 сент, 21:37, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Sep 26, 2008, at 1:09 PM, Alex K wrote: > > > > > Thanks, Michael. > > > I've just tried your example with column_property, everything works > >

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Doug Farrell
Michael, You're right of course, your version works fine. I cut and pasted what you have into my code framework, cleaned up some stuff and it works there as well. One thing I cleaned up was this: # initialize the mysql engine and SqlAlchemy base objects engine = create_engine(__config__.da

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Michael Bayer
Doug -what happened with the example I pasted ?  It generates the exact SQL you describe.   A full script is attached, using the mappings you've sent.  It uses sqlite, so you can just run it.from sqlalchemy import * from sqlalchemy.orm import * engine = create_engine('sqlite://', echo=True) metada

[sqlalchemy] Re: best practice for group by / count

2008-09-26 Thread Steven
Michael, Thanks perfect response. Got me to where I need to be. Still getting used to when things are just queries vs actually being executed i tacked on an ".all()" there at the end... and it works prefect. Steven On Sep 26, 12:00 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Se

[sqlalchemy] Re: best practice for group by / count

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 2:42 PM, Steven wrote: > > Sorry for being the newbie.. i just tried the "many-to-many" example > that you provided: > > records = > meta.Session.query(func.count("*").label('cnt'), > model > .Tag > ).filter > (model.Tag.id==model.pagetag_table.c.tagid).group_by(model.Tag.nam

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Doug Farrell
Michael, Thanks for your help once again. Unfortunately I'm just not 'getting it'; I can't make the query work the way you describe. So I'm bailing out and going back to plan SQL statements till I have more time to work on this. Again, thanks for your help and guidance, I'm determined to m

[sqlalchemy] Re: best practice for group by / count

2008-09-26 Thread Steven
Sorry for being the newbie.. i just tried the "many-to-many" example that you provided: records = meta.Session.query(func.count("*").label('cnt'), model.Tag).filter(model.Tag.id==model.pagetag_table.c.tagid).group_by(model.Tag.name, model.Tag.id).order_by(model.Tag.name.asc()) ==

[sqlalchemy] Re: best practice for group by / count

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 12:40 PM, Steven wrote: > > I'm new to SQLAlchemy and still getting used to it. I'm trying to > learn how to use the higer level apis.. the mapped objects. I still > think in SQL and then have to work "backwards" to figure out how to > best get SQLAlchemy to do something si

[sqlalchemy] Re: query over multiple any2many relations?

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 2:56 PM, [EMAIL PROTECTED] wrote: > > hmm. the joins are ... hard to generate, especialy in proper/sensible > combinations. (i've nearly given up on pushing further my > python-expression-to-sa converter, the logic fails on 1/3 of the > a.b.c join-cases.) sorry you've given

[sqlalchemy] Re: best practice for group by / count

2008-09-26 Thread Steven
Thanks.. make more sense now ( I suppose it generally does once someone else has solved it for you ). Hmm... it almost looks like a little tool for beginners could be created where you enter a sql statement and it generates the corresponding SQLAlchemy call. Thanks again. On Sep 26, 10:50 am, M

[sqlalchemy] Re: query over multiple any2many relations?

2008-09-26 Thread az
> > hi > > say i have Person, Address, Street: > > person has (many) addresess, address has (many) streets, > > ... could be more levels down; and the relations are m2m for > > better taste (: > > how should the query 'who lives at street X', or > > "who lives at street with .name.startswith('A')"

[sqlalchemy] Re: Best practice for cross-package foreign keys

2008-09-26 Thread Petter Urkedal
Thanks, that's what I needed to know. The use for limiting the scope of drop_all is to avoid removing data from the base package when uninstalling one of the dependent packages. In the case of create_all, it's unlimited scope is probably ok, since it will only create the missing tables. PS: Sor

[sqlalchemy] Re: Comparable Property in partial selects

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 1:09 PM, Alex K wrote: > > Thanks, Michael. > > I've just tried your example with column_property, everything works > fine, except one thing: > > Does column_property hides the properties it relies on? > > So, once I added full_name, last_name and first_name disappeared, is >

[sqlalchemy] Re: Comparable Property in partial selects

2008-09-26 Thread Michael Bayer
Using comparable property as a selected element in SQL is a use case which hasn't been addressed as of yet - the main usage was so far just for producing WHERE/ORDER BY/etc. expressions. In particular, the comparable property doesn't have any query setup capabilities (i.e. where it puts

[sqlalchemy] Re: Comparable Property in partial selects

2008-09-26 Thread Alex K
Thanks, Michael. I've just tried your example with column_property, everything works fine, except one thing: Does column_property hides the properties it relies on? So, once I added full_name, last_name and first_name disappeared, is it possible to have them existing along with full_name? Alex

[sqlalchemy] best practice for group by / count

2008-09-26 Thread Steven
I'm new to SQLAlchemy and still getting used to it. I'm trying to learn how to use the higer level apis.. the mapped objects. I still think in SQL and then have to work "backwards" to figure out how to best get SQLAlchemy to do something similar. ===

[sqlalchemy] Re: 0.5 error (not in 0.4) trying to call decode on Oracle LOB .decode in types.py

2008-09-26 Thread picoplex
Michael, You are right, I have been using "String" with no length when I want a CLOB column and "Unicode" for varchar2 datatypes in my Entity definitions (using Elixir). I'll change my model to explicitly use UnicodeText. N.B. This change in behaviour is noted in the 05Migration notes as you sa

[sqlalchemy] Re: DateTime bug probably

2008-09-26 Thread Christoph Zwerschke
mraer schrieb: > This simple test fails with error: > DataError: (DataError) unable to parse time None None Which version are you using? Your test works for me (except I needed to change "Mapper" to "mapper") with SA 0.5rc1 and psycopg 2.0.8, Py 2.5, Postgres 8.3.1 on WinXP. As an aside, you s

[sqlalchemy] Re: DateTime bug probably

2008-09-26 Thread mraer
My configuration is: Python 2.5 SA 0.5rc1 psycopg 2.0.8 Postgres 8.3.4 Windows XP The problem was in locale. I have russian locale and Moscow time zone. DB had configuration which outputed this date (in 1919 year) as string: "1919-01-01 15:04:48+03:30:48". Look at time zone offset. Psycopg2 fails

[sqlalchemy] Re: 0.5 error (not in 0.4) trying to call decode on Oracle LOB .decode in types.py

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 11:23 AM, picoplex wrote: > > The code that chokes with SA 0.5.0rc1 is as follows: > > filteredRecords = > theChildClass > .query().filter(filterString).join(relationshipToParentName, > aliased > =requiresAliased).filter(parentFilterString).order_by(orderByString) > [start:(s

[sqlalchemy] Re: 0.5 documentation request

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 11:40 AM, Jon wrote: > > I have a request for the 0.5 documentation. > I spent /way/ too much time looking for the functionality provided by > the version_id_col Mapper __init__ param. For those of us using > database structures formerly (or still) in use by hibernate this is

[sqlalchemy] Comparable Property in partial selects

2008-09-26 Thread Alex K
Hi All, I have created comparable property "JoinedValues" that represents any joined columns, e.g. full name for first_name and last_name. Everything works, fine, except the moment when I try to select this property explicitly, e.g. like: session.query(User.full_name)... i get error " 'ClauseLis

[sqlalchemy] 0.5 documentation request

2008-09-26 Thread Jon
I have a request for the 0.5 documentation. I spent /way/ too much time looking for the functionality provided by the version_id_col Mapper __init__ param. For those of us using database structures formerly (or still) in use by hibernate this is a big deal. Therefore, I request a slight bump in it

[sqlalchemy] Re: 0.5 error (not in 0.4) trying to call decode on Oracle LOB .decode in types.py

2008-09-26 Thread picoplex
The code that chokes with SA 0.5.0rc1 is as follows: filteredRecords = theChildClass.query().filter(filterString).join(relationshipToParentName, aliased=requiresAliased).filter(parentFilterString).order_by(orderByString) [start:(start+limit)] where: theChildClass: blnver filterString: '1=1'

[sqlalchemy] Re: Two foreignkey's to the same table, rendering a join error.

2008-09-26 Thread Michael Bayer
Information on "primaryjoin" and "secondaryjoin" is available at: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_customjoin On Sep 25, 2008, at 8:18 PM, Jorge Vargas wrote: > > hello I'm having a bit of troubles with the following case. > > http://paste.turbogears.org/p

[sqlalchemy] Re: Best practice for cross-package foreign keys

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 6:25 AM, Petter Urkedal wrote: > > I have a package which implements users, groups, and access control > using > SQLAlchemy. On top of that I'm writing applications as separate > packages. > These will make foreign keys into the tables of the user management > package. > At

[sqlalchemy] Re: query over multiple any2many relations?

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 6:59 AM, [EMAIL PROTECTED] wrote: > > hi > say i have Person, Address, Street: > person has (many) addresess, address has (many) streets, > ... could be more levels down; and the relations are m2m for better > taste (: > how should the query 'who lives at street X', or > "who

[sqlalchemy] Re: How to perform inner joins

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 9:23 AM, Doug Farrell wrote: > I'm trying to represent a many-to-many relationship between the > press_table and the press_routing table using the linking table, > press_routing_press. I think I've got the table structure and > mapping set up, but now I need some help to

[sqlalchemy] Re: DateTime bug probably

2008-09-26 Thread Michael Bayer
SQLAlchemy's PGDateTime object does nothing, so its likely the issue you're having is a psycopg2 issue. You should ask on their list (using psycopg2-only code). On Sep 26, 2008, at 5:28 AM, mraer wrote: > > This simple test fails with error: > DataError: (DataError) unable to parse time No

[sqlalchemy] Re: 0.5 error (not in 0.4) trying to call decode on Oracle LOB .decode in types.py

2008-09-26 Thread Michael Bayer
On Sep 26, 2008, at 9:39 AM, picoplex wrote: > > I have been porting an app from Windows to linux. > > Whereas the windows app using SA 0.4.5 worked fine, I had a SA erro > with the installed version on Linux - SA 0.4.0 (AttributeError: 'list' > object has no attribute 'values' in get_children i

[sqlalchemy] 0.5 error (not in 0.4) trying to call decode on Oracle LOB .decode in types.py

2008-09-26 Thread picoplex
I have been porting an app from Windows to linux. Whereas the windows app using SA 0.4.5 worked fine, I had a SA erro with the installed version on Linux - SA 0.4.0 (AttributeError: 'list' object has no attribute 'values' in get_children in expression.py). I therefore upgraded SA on linux to th

[sqlalchemy] How to perform inner joins

2008-09-26 Thread Doug Farrell
Hi all, Well, I'm still stumped by SqlAlchemy syntax, but it's getting better. I've got some tables built this way using SqlAlchemy 0.5: press_table = Table('press', metadata, autoload=True) press_routing_table = Table('press_routing', metadata, autoload=True) press_routing_press_table

[sqlalchemy] Best practice for cross-package foreign keys

2008-09-26 Thread Petter Urkedal
I have a package which implements users, groups, and access control using SQLAlchemy. On top of that I'm writing applications as separate packages. These will make foreign keys into the tables of the user management package. At the moment I use separate metadata for each package, and the foreign

[sqlalchemy] Re: query over multiple any2many relations?

2008-09-26 Thread Alex K
Hi, I was only able to achieve this via joins and eagerloads, so I would be also interested in the relations based example Alex On 26 сент, 14:59, [EMAIL PROTECTED] wrote: > hi > say i have Person, Address, Street: >  person has (many) addresess, address has (many) streets, > ... could be more l

[sqlalchemy] Re: Problems with join query, can't figure out what's wrong. Noob alert!

2008-09-26 Thread olavgg
Thank you again for a great answer. It seems like I lack full knowledge about how the basic things works with SqlAlchemy and Elixir. I'll try to start from scratch, read the documentation better and follow your suggestions when I rebuild. Thank you for your help. --~--~-~--~~-

[sqlalchemy] query over multiple any2many relations?

2008-09-26 Thread az
hi say i have Person, Address, Street: person has (many) addresess, address has (many) streets, ... could be more levels down; and the relations are m2m for better taste (: how should the query 'who lives at street X', or "who lives at street with .name.startswith('A')" look like? is it expres

[sqlalchemy] DateTime bug probably

2008-09-26 Thread mraer
This simple test fails with error: DataError: (DataError) unable to parse time None None def testDate1919(self): class DateHolder(object): def __init__(self, date): self.date = date metadata = MetaData() dateTable = Table( "date",