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

2007-02-27 Thread Pradeep
I have a expenses table with a amount field. I have mapped that table to a Expense entity object. How do I sum up all the amounts using my entity object.? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy

[sqlalchemy] Re: Spatial data (PostGIS/OGC) with SqlAlchemy

2007-02-27 Thread Allen Bierbaum
I just wanted to give an update. I have found a solution that works ok for now but I had to hack a bit. I ended up having to use psycopg2's ability to override how python classes are converted to/from a database. psycopg2 seems to have more complete support for this then SA, so it let me

[sqlalchemy] How do I get columns in sqlalchemy group by function

2007-02-27 Thread vinjvinj
I have the following columns in some of my select columns: group_by_column = sqlalchemy.func.sum(column1) How do I get column1 from the group_by_column object (In other words is there any way to find out what columns the function is going to be applied to?). I did a dir(group_by_column) and saw

[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: Spatial data (PostGIS/OGC) with SqlAlchemy

2007-02-27 Thread Michael Bayer
these are all SA bugs/possible inaccuracies in API usage. you should be able to execute the function as I described below, you should be able to put the function into an INSERT statement as well. Ill test these features later today. On Feb 25, 2007, at 3:43 PM, Allen Bierbaum wrote: I

[sqlalchemy] Auto-joins via FK

2007-02-27 Thread Rick Morrison
Shouldn't SA be able to figure out the following joins without needing the explicit join params? I've got to be missing something dumb. from sqlalchemy import * metadata = BoundMetaData('sqlite:///:memory:') ent = Table('entity', metadata, Column('id', INT,

[sqlalchemy] Re: Spatial data (PostGIS/OGC) with SqlAlchemy

2007-02-27 Thread Michael Bayer
OK, for the function execution, the syntax that works with release 0.3.5 is: conn = db.connect() trans = conn.begin() conn.execute(func.AddGeometryColumn ('','gis_entity','fpos',-1,'LINESTRING',2).select()) trans.commit() conn.close() notice it just adds a select().in changeset 2364, you

[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: Auto-joins via FK

2007-02-27 Thread Michael Bayer
the join() function, given two tables, will make a foreign key join condition by default if you dont specify the onclause. but if you arent using a join function somewhere, then nothing else is going to generate any clauses for you. On Feb 27, 2007, at 10:50 AM, Rick Morrison wrote:

[sqlalchemy] Re: contains_eager is somehow not loading all the instances.

2007-02-27 Thread Michael Bayer
if you run it with full blown logging on, i.e.: import logging logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) logging.getLogger('sqlalchemy.orm').setLevel(logging.DEBUG) the issue can be detected when you look at the mapper creating instance keys for T

[sqlalchemy] Re: contains_eager is somehow not loading all the instances.

2007-02-27 Thread Dennis
Thanks for taking a peek. Interesting, it does indeed fix the issue to use labels. Now I have another issue though, I have a case statement in my select which I was specifying like this: select ( ['case when yada yada yada end as something' ] .. If use_labels = True, then the query

[sqlalchemy] Re: contains_eager is somehow not loading all the instances.

2007-02-27 Thread Michael Bayer
the label is always tablename_columnname. youd have to show me where you need that to be programmatic. On Feb 27, 2007, at 2:29 PM, Dennis wrote: Thanks for taking a peek. Interesting, it does indeed fix the issue to use labels. Now I have another issue though, I have a case statement

[sqlalchemy] Print of returned object fails

2007-02-27 Thread Gloria
I am not able to print the object returned by sqlAlchemy in this instance: clients=Table('clients',metadata, autoload=True) s = clients.select(clients.c.client_id==client_id) #print str(s) result = s.execute() client = result.fetchone() print

[sqlalchemy] Re: contains_eager is somehow not loading all the instances.

2007-02-27 Thread Dennis
Well, columnname isn't a simple column in the case of a case statement... the label is turning out like this: casewhenhas_testtrueandscoreisnullandgender1then1whenscoreisnullthen2elsescoreend I haven't found a way to manually assign a label to a text clause yet, but before I tried

[sqlalchemy] rev2362 fixes one thing and breaks another

2007-02-27 Thread sdobrev
hallo. AFAIsee rev 2362 fixes the lazy-load for polymorphic properties. but is seems to introduce another problem.. or maybe uncover it. table-inheritance, A-B-C-D, and A has reference to B. 2361: lazy-ref is loaded wrong ... File /home/az/src/hor-trunk/db/sawrap/tests/sa_gentestbase.py,