Crystal clear, thank you very much! On Dec 20, 3:56 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > The execute() method of Connection and Engine passes through parameters > unchanged to cursor.execute() or cursor.executemany(), depending on their > structure, if you pass the method a plain SQL string followed by the > parameters: > > connection.execute("SELECT * FROM table WHERE id=? AND foo=?", 25, > 'bar') > > The usage of "?" is dependent on the accepted paramstyles of the underlying > DBAPI. A DBAPI may accept "qmark" (?), "format" (%s), "numeric" (:1, :2, > :3), or no positional style at all. You'd need to consult its documentation > for details. > > When using Session, acquire the current connection using conn = > Session.connection(). > > On Dec 20, 2010, at 8:10 AM, neurino wrote: > > > > > How can I execute a query like if I'm using the normal python DB API, > > passing params as a sequence and not as a mapping? > > > Something like: > > > myParams = (1, 1, 2, 51, 3, 101, 4, 151, 6, 201, 7, 251) > > > Session.execute(""" > > SELECT T.datetime, MAX(T.v0), MAX(T.v1), MAX(T.v2), MAX(T.v3), > > MAX(T.v4), MAX(T.v5) FROM ( > > > SELECT data.value AS v0, NULL AS v1, NULL AS v2, NULL AS v3, > > NULL AS v4, NULL AS v5 > > FROM acquisitions INNER JOIN data > > ON acquisitions.id = data.id_acq > > WHERE acquisitions.id_centr=? and dati.id_mis=? > > > UNION > > > SELECT NULL AS v0, data.value AS v1, NULL AS v2, NULL AS v3, > > NULL AS v4, NULL AS v5 > > FROM acquisitions INNER JOIN data > > ON acquisitions.id = data.id_acq > > WHERE acquisitions.id_centr=? and dati.id_mis=? > > > UNION > > > SELECT NULL AS v0, NULL AS v1, data.value AS v2, NULL AS > > v3, NULL AS v4, NULL AS v5 > > FROM acquisitions INNER JOIN data > > ON acquisitions.id = data.id_acq WHERE > > acquisitions.id_centr=? and dati.id_mis=? > > > UNION > > > SELECT NULL AS v0, NULL AS v1, NULL AS v2, data.value AS > > v3, NULL AS v4, NULL AS v5 > > FROM acquisitions INNER JOIN data > > ON acquisitions.id = data.id_acq > > WHERE acquisitions.id_centr=? and dati.id_mis=? > > > UNION > > > SELECT NULL AS v0, NULL AS v1, NULL AS v2, NULL AS v3, > > data.value AS v4, NULL AS v5 > > FROM acquisitions INNER JOIN data > > ON acquisitions.id = data.id_acq > > WHERE acquisitions.id_centr=? and dati.id_mis=? > > > UNION > > > SELECT NULL AS v0, NULL AS v1, NULL AS v2, NULL AS v3, NULL AS > > v4, data.value AS v5 > > FROM acquisitions INNER JOIN data > > ON acquisitions.id = data.id_acq > > WHERE acquisitions.id_centr=? and dati.id_mis=? > > > ) AS T GROUP BY T.datetime""", > > > myParams > > > ) > > > Of course the number of UNIONs is not fixed and is built on lenght of > > given tuple. > > > I searched around for it but I see Session.execute just accept bind > > params as a mapping. > > > Thank you for your support > > > -- > > 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 > > athttp://groups.google.com/group/sqlalchemy?hl=en.
-- 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.