On Jun 9, 2012, at 4:24 AM, CJ Lee wrote: > Thanks Michael, > Does anyone know a way of retrieving column info from a select > statement? > my eventual goal is: mimic a 'select into..' or a 'create table t as > select...' from one database / engine into another. > my strategy is to > 1. execute a select on engine1. > 2. get result Column metadata from resultProxy > 3. create table with that metadata in engine2 > 4. using resultproxy insert into new table > > I can't figure out step2. > I can see resultproxy.context.result_map seems to have a list of > tuples that bear that info but it feels a little hacky.
The way this is done is to just reuse the same Table object with both databases. When you "execute a select", the select() construct there is where you get the column/type information from. As far as result proxy, you can get the names of the keys using result.keys(), and if you wanted, the DBAPI's view of this from a SELECT statement using result.cursor.description, but the SQLAlchemy-level information is all passed in to the execute() method. It might not be a bad idea to add accessors to ResultProxy for this too, but it would just be pointing to the select() in any case. That is: for key in resultproxy.keys(): column = my_select_statement.c[key] > > On Jun 8, 1:45 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: >> postfetch_cols() only applies to INSERT and UPDATE statements where defaults >> might have been fired off. Currently the execution context doesn't take the >> step of placing a blank collection (or raising an error) in the case of >> statements where this collection does not apply. >> >> On Jun 8, 2012, at 7:24 AM, CJ Lee wrote: >> >> >> >> >> >> >> >>> I've looked in the source sqlalchemy/engine/base.py under the class >>> ExecutionContext and it does not contain this methodpostfetch_cols() >>> as documented. I've checked in 0.7.7, 0.6.9 stable versions as well as >>> 0.8 am I being silly and missing something? >> >>> Details here: >>> http://stackoverflow.com/questions/10924160/sqlalchemy-executionconte... >> >>> -- >>> 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 >>> 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 sqlalchemy@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. > -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.