On 12 Feb 2010, at 19:36, Michael Bayer wrote:
Ed Singleton wrote:
class InsertFromSelect(ClauseElement):
def __init__(self, table, select):
self.table = table
self.select = select
@compiles(InsertFromSelect)
def visit_insert_from_select(element, compiler, **kw):
return "INSERT INTO %s (%s) %s" % (
compiler.process(element.table, asfrom=True),
", ".join([col.name for col in element.select.columns]),
compiler.process(element.select),
)
add the mixin sqlalchemy.sql.expression._Executable to your
InsertFromSelect class. I'm going to rename it to "Executable"
and will
add it to the docs now.
Okay, I've modified it to this, and it seems to work perfectly
from sqlalchemy.sql.expression import ClauseElement, _Executable
class InsertFromSelect( _Executable, ClauseElement):
def __init__(self, table, select):
self.table = table
self.select = select
@compiles(InsertFromSelect)
def visit_insert_from_select(element, compiler, **kw):
return "INSERT INTO %s (%s) %s" % (
compiler.process(element.table, asfrom=True),
", ".join([col.name for col in element.select.columns]),
compiler.process(element.select),
)
Thanks for all your help. You are a king. (If not one who leads me
to throw away the hacking I did on SA. And I was so close to getting
it working).
Ed
--
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.