Re: [sqlalchemy] group by and Oracle
Yes, Ian, it works, :-) thank you j Ian Kelly wrote: On Fri, Dec 3, 2010 at 4:08 AM, jo jose.soa...@sferacarta.com wrote: Hi all, I'm trying to write a GROUP BY query grouped by a function (to_char) using a variable format, which could be 'yy' or '' as in: sql=session.query( func.to_char(Prestazione.c.data,format), func.sum(Prestazione.c.quantita).label('quantita'), func.sum(Prestazione.c.importo).label('importo') ) sql=sql.filter(Verifica.c.codice == Tariffa.c.codice) sql=sql.filter(Prestazione.c.id_tariffa == Tariffa.c.id) sql=sql.group_by(Verifica.c.codice, func.to_char(Prestazione.c.data,format)) Have you tried using the same func result in both places, i.e.: to_char = func.to_char(Prestazione.c.data,format) sql=session.query( to_char, func.sum(Prestazione.c.quantita).label('quantita'), func.sum(Prestazione.c.importo).label('importo') ) sql=sql.filter(Verifica.c.codice == Tariffa.c.codice) sql=sql.filter(Prestazione.c.id_tariffa == Tariffa.c.id) sql=sql.group_by(Verifica.c.codice, to_char) -- Jose Soares Sferacarta Net Via Bazzanese 69 40033 Casalecchio di Reno Bologna - Italy Ph +39051591054 fax +390516131537 web:www.sferacarta.com Le informazioni contenute nella presente mail ed in ogni eventuale file allegato sono riservate e, comunque, destinate esclusivamente alla persona o ente sopraindicati, ai sensi del decreto legislativo 30 giugno 2003, n. 196. La diffusione, distribuzione e/o copiatura della mail trasmessa, da parte di qualsiasi soggetto diverso dal destinatario, sono vietate. La correttezza, l’integrità e la sicurezza della presente mail non possono essere garantite. Se avete ricevuto questa mail per errore, Vi preghiamo di contattarci immediatamente e di eliminarla. Grazie. This communication is intended only for use by the addressee, pursuant to legislative decree 30 June 2003, n. 196. It may contain confidential or privileged information. You should not copy or use it to disclose its contents to any other person. Transmission cannot be guaranteed to be error-free, complete and secure. If you are not the intended recipient and receive this communication unintentionally, please inform us immediately and then delete this message from your system. Thank you. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] group by and Oracle
Hi all, I'm trying to write a GROUP BY query grouped by a function (to_char) using a variable format, which could be 'yy' or '' as in: sql=session.query( func.to_char(Prestazione.c.data,format), func.sum(Prestazione.c.quantita).label('quantita'), func.sum(Prestazione.c.importo).label('importo') ) sql=sql.filter(Verifica.c.codice == Tariffa.c.codice) sql=sql.filter(Prestazione.c.id_tariffa == Tariffa.c.id) sql=sql.group_by(Verifica.c.codice, func.to_char(Prestazione.c.data,format)) it works fine in PostgreSQL... pg: SELECT to_char(prestazione.data, %(to_char_2)s) AS to_char_1, sum(prestazione.quantita) AS quantita, sum(prestazione.importo) AS importo FROM prestazione, verifica, tariffa WHERE verifica.codice = tariffa.codice AND prestazione.id_tariffa = tariffa.id AND prestazione.aa_bolletta = %(aa_bolletta_1)s AND prestazione.nr_bolletta = %(nr_bolletta_1)s AND prestazione.sezionale = %(sezionale_1)s GROUP BY verifica.codice, to_char(prestazione.data, %(to_char_3)s) {'to_char_2': '', 'nr_bolletta_1': 1, 'aa_bolletta_1': 2009, 'sezionale_1': u'53', 'to_char_3': ''} Col ('to_char_1', 'quantita', 'importo') Row (u'2009', Decimal('1.000'), Decimal('482.000')) Out[1]: (u'2009', Decimal('1.000'), Decimal('482.000')) ... but Oracle... DatabaseError: (DatabaseError) ORA-00979: not a GROUP BY expression 'SELECT to_char(prestazione.data, :to_char_2) AS to_char_1, sum(prestazione.quantita) AS quantita, sum(prestazione.importo) AS importo FROM prestazione, verifica, tariffa WHERE verifica.codice = tariffa.codice AND prestazione.id_tariffa = tariffa.id AND prestazione.aa_bolletta = :aa_bolletta_1 AND prestazione.nr_bolletta = :nr_bolletta_1 AND prestazione.sezionale = :sezionale_1 GROUP BY verifica.codice, to_char(prestazione.data, :to_char_3)' {'to_char_2': '', 'nr_bolletta_1': 1, 'aa_bolletta_1': 2010, 'sezionale_1': u'53', 'to_char_3': ''} version: SA 0.6beta3 Thanks for any help j -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] group by and Oracle
On Fri, Dec 3, 2010 at 4:08 AM, jo jose.soa...@sferacarta.com wrote: Hi all, I'm trying to write a GROUP BY query grouped by a function (to_char) using a variable format, which could be 'yy' or '' as in: sql=session.query( func.to_char(Prestazione.c.data,format), func.sum(Prestazione.c.quantita).label('quantita'), func.sum(Prestazione.c.importo).label('importo') ) sql=sql.filter(Verifica.c.codice == Tariffa.c.codice) sql=sql.filter(Prestazione.c.id_tariffa == Tariffa.c.id) sql=sql.group_by(Verifica.c.codice, func.to_char(Prestazione.c.data,format)) Have you tried using the same func result in both places, i.e.: to_char = func.to_char(Prestazione.c.data,format) sql=session.query( to_char, func.sum(Prestazione.c.quantita).label('quantita'), func.sum(Prestazione.c.importo).label('importo') ) sql=sql.filter(Verifica.c.codice == Tariffa.c.codice) sql=sql.filter(Prestazione.c.id_tariffa == Tariffa.c.id) sql=sql.group_by(Verifica.c.codice, to_char) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.