Hi everyone, I'm trying to implement an InsertFromSelect workaround to
handle the identity insert issue of SQL server. This is more or less
what I'm doing:

class InsertFromSelect(Executable, ClauseElement) :
    def __init__(self, table, select) :
        self.table = table
        self.select = select

@compiler.compiles(InsertFromSelect, "mssql")
def visit_insert_from_select(element, compiler, **kw) :
    tab_name = compiler.process(element.table, asfrom=True)
    q = "SET IDENTITY_INSERT %s ON;" %(tab_name)
    q += "INSERT INTO %s (%s) %s;" % (tab_name,
        ', '.join([compiler.process(c) for c in element.table.c]),
        compiler.process(element.select))
    q += "SET IDENTITY_INSERT %s OFF;" %(tab_name)
    return q

insert_from_select = InsertFromSelect(new_table, old_table))
engine.execute(insert_from_select)

The code is executed without error, but 'new_table' is not filled.
Important: in my code I cannot use the session to execute the query.
Can anyone point me out what I'm doing wrong?
Thanks!

-- 
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.

Reply via email to