[sqlalchemy] Re: group_by and column labels

2007-06-08 Thread Huy Do

Michael Bayer wrote:
 On Jun 7, 2007, at 7:17 AM, Huy Do wrote:

   
 Michael Bayer wrote:
 
 put strings into group_by:

 group_by = [client_code, client_name, ...]

   
 Hi Michael,

 Sorry I'm not sure what you are suggesting. I don't really want to
 retype my column names again in the group_by clause.

 

 i was suggesting a workaround.
   
just thought i might have missed something. thanks.
 My intention was to be able to reuse the actual column list in the  
 group
 by clause.
 

 would be easier if you can wait for 0.4 on that.

   
Not a problem.

Just though it was a nice thing to have, because I have always hated 
retyping all those columns names when i need group by in my sql.

Thanks

Huy



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: group_by and column labels

2007-06-08 Thread Huy Do

Hi Rick,

If this works, that is fine for me. I just don't want to retype my 
columns to avoid errors.

I'll test and then send an update.

Thanks

Huy
 I think the .name property of a labled column holds the label, so how 
 about

 
 db.job_table, db.client_table, db.service_type_table],
  group_by = [col.name http://col.name for col in group_by],
 


 On 6/7/07, *Michael Bayer* [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:



 On Jun 7, 2007, at 7:17 AM, Huy Do wrote:

 
  Michael Bayer wrote:
  put strings into group_by:
 
  group_by = [client_code, client_name, ...]
 
 
  Hi Michael,
 
  Sorry I'm not sure what you are suggesting. I don't really want to
  retype my column names again in the group_by clause.
 

 i was suggesting a workaround.

  My intention was to be able to reuse the actual column list in the
  group
  by clause.

 would be easier if you can wait for 0.4 on that.



 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: group_by and column labels

2007-06-08 Thread Huy Do


 I think the .name property of a labled column holds the label, so how 
 about

 
 db.job_table, db.client_table, db.service_type_table],
  group_by = [col.name http://col.name for col in group_by],
 

 
This almost worked, but not quite. Using the name column, does give me 
the label, but it also only gives the column name, which is a problem 
when you have tables with the same column in the from clause (Ambiguous 
column error from the db server). The select column statement has 
table.column_name whilst the group by (using the method above) only 
has column_name or label_name.

If i use use_labels option for the select statement, it works, because 
then the label names are unique across all columns.

thanks

Huy
 On 6/7/07, *Michael Bayer* [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:



 On Jun 7, 2007, at 7:17 AM, Huy Do wrote:

 
  Michael Bayer wrote:
  put strings into group_by:
 
  group_by = [client_code, client_name, ...]
 
 
  Hi Michael,
 
  Sorry I'm not sure what you are suggesting. I don't really want to
  retype my column names again in the group_by clause.
 

 i was suggesting a workaround.

  My intention was to be able to reuse the actual column list in the
  group
  by clause.

 would be easier if you can wait for 0.4 on that.



 
 





--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: group_by and column labels

2007-06-07 Thread Huy Do

Michael Bayer wrote:
 put strings into group_by:

 group_by = [client_code, client_name, ...]
   

Hi Michael,

Sorry I'm not sure what you are suggesting. I don't really want to 
retype my column names again in the group_by clause.

My intention was to be able to reuse the actual column list in the group 
by clause.

Thanks,


Huy



 On Jun 6, 2007, at 7:07 PM, Huy Do wrote:

   
 Hi,

 I am trying to reuse my column list in my group by clause but some  
 of my
 columns use label() which is causing a sql syntax error because of the
 column as label in the group by clause. Is it possible to get the
 group_by to only use the label side of a column .

 eg. (This doesn't work because of the labels
 group_by = [
 service.date,
 service.client_id,
 service_type.type_code,
 service.service_code,
 client.code.label('client_code'),
 client.name.label('client_name'),
 func.coalesce(func.nullif(client_rate.description,  
 ''),
 service_type.description).label('service_description'),
 service.rate_amt
 ]
 columns = group_by[:].extend([
 func.sum(service.quantity).label('quantity'),
 func.sum(service.service_amt).label('service_amt')
 ])

 s = select(columns, criteria,
 from_obj=[outerjoin(db.service_table,  
 db.client_rate_table),
 db.job_table, db.client_table, db.service_type_table],
 group_by=group_by,
 order_by=[service.date, client.name, service.service_code]
 )

 Many thanks,

 Huy

 





--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---