Skip to content

Instantly share code, notes, and snippets.

@Stiivi
Created April 12, 2014 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stiivi/10549265 to your computer and use it in GitHub Desktop.
Save Stiivi/10549265 to your computer and use it in GitHub Desktop.
class CreateTableAsSelect(Executable, ClauseElement):
def __init__(self, table, select):
self.table = table
self.select = select
@compiles(CreateTableAsSelect)
def visit_create_table_as_select(element, compiler, **kw):
preparer = compiler.dialect.preparer(compiler.dialect)
full_name = preparer.format_table(element.table)
return "CREATE TABLE %s AS (%s)" % (
element.table,
compiler.process(element.select)
)
@compiles(CreateTableAsSelect, "sqlite")
def visit_create_table_as_select(element, compiler, **kw):
preparer = compiler.dialect.preparer(compiler.dialect)
full_name = preparer.format_table(element.table)
return "CREATE TABLE %s AS %s" % (
element.table,
compiler.process(element.select)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment