I have a script.py that does roughly this:

import sqlalchemy as sa

engine = ...

part_text = """RANGE COLUMNS (my_date) (
    PARTITION p20161017 VALUES LESS THAN ('2016-10-18'),
    PARTITION p20161018 VALUES LESS THAN ('2016-10-19'),
    PARTITION p99991231 VALUES LESS THAN (MAXVALUE)
)"""

t = sa.Table(
    'test',
    sa.MetaData(),
    sa.Column('test_id', sa.INTEGER),
    sa.Column('my_date', sa.DATE),
    mysql_stats_sample_pages='4',
    mysql_partition_by=part_text
)

print(sa.schema.CreateTable(t).compile(engine))



The order of the table and partition options are not respected 
(https://dev.mysql.com/doc/refman/5.7/en/create-table.html) and this causes 
a syntax error. It looks like this has to do with Table using kwargs. While 
I can move up to 3.6, would that even fix the issue in this situation? Is 
there some way I can get this working properly without upgrading SQLAlchemy?

$ PYTHONHASHSEED=100 python script.py    # invalid SQL

CREATE TABLE test (
        test_id INTEGER, 
        my_date DATE
)PARTITION BY RANGE COLUMNS (my_date) (
    PARTITION p20161017 VALUES LESS THAN ('2016-10-18'),
    PARTITION p20161018 VALUES LESS THAN ('2016-10-19'),
    PARTITION p99991231 VALUES LESS THAN (MAXVALUE)
) STATS_SAMPLE_PAGES=4





$ PYTHONHASHSEED=1 python script.py      # correct SQL

CREATE TABLE test (
        test_id INTEGER, 
        my_date DATE
)STATS_SAMPLE_PAGES=4 PARTITION BY RANGE COLUMNS (my_date) (
    PARTITION p20161017 VALUES LESS THAN ('2016-10-18'),
    PARTITION p20161018 VALUES LESS THAN ('2016-10-19'),
    PARTITION p99991231 VALUES LESS THAN (MAXVALUE)
)



-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to