On Thu, Nov 30, 2017 at 5:32 AM, su-sa <sachdeva.sugandh...@gmail.com> wrote:
> Hi everyone,
>
> does someone maybe know if one can from the dialect somehow influence what
> CREATE TABLE statement would be generated in certain cases?
>
> So for example: In the tests for temporary table I saw that for Oracle, the
> create table statement has been adjusted, but that only ís a hack to make
> the tests pass and what if someone really wants to create a temporary table
> using oracle(for ex. CREATE GLOBAL TEMPORARY TABLE) and sqlalchemy?  As far
> as I understood, one cannot in the sqlalchemy framework influence the CREATE
> TABLE statement, or am I wrong?
>
> Another question, is there also a way in sqlalchemy to specify if one wants
> to make a column table or row table? Couldn't really find something similar.

If you just want simple CREATE <something> TABLE, use the prefixes argument:

from sqlalchemy import *
from sqlalchemy.schema import CreateTable

m = MetaData()
t = Table(
    't', m, Column('x', Integer),
    prefixes=["GLOBAL", "TEMPORARY"]
)

print CreateTable(t)

for more elaborate things you can affect CREATE TABLE by providing a
compiler function for the CreateTable class:

from sqlalchemy import *
from sqlalchemy.schema import CreateTable
from sqlalchemy.ext.compiler import compiles

@compiles(CreateTable)
def _add_global_thing(element, compiler, **kw):
    text = compiler.visit_create_table(element, **kw)
    if element.element.info.get('global_temporary', False):
        text = text.replace("CREATE TABLE", "CREATE GLOBAL TEMPORARY TABLE")
    return text

m = MetaData()
t = Table(
    't', m, Column('x', Integer),
    info={"global_temporary": True}
)

print CreateTable(t)



>
> Thanks in advance,
> S
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to