this would be a bug since we do have a list of entries that are dependent on each other, so orderings like these need to be coded. https://bitbucket.org/zzzeek/sqlalchemy/issues/3961/mysql-partition-options-need-to-be-after is added which per the syntax diagram moves all the partition options to the end, however this is targeted for 1.2 at the moment.

Right now the table.kwargs is a view into an intricate object that validates the kwargs and such and is not that simple to turn into an OrderdedDict right now. For a workaround you'd probably need to do a regular expression in conjunction with a CreateTable recipe:

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

@compiles(CreateTable, "mysql")
def _fix_args(element, compiler, **kw):
    text = compiler.visit_create_table(element, **kw)
    sample_pages = element.kwargs.get('mysql_stats_sample_pages')
    if sample_pages:
        text = re.sub(r'STATS_SAMPLE_PAGES=\d+', '', text)
        # append to the end
        text += 'STATS_SAMPLE_PAGES=%s' % sample_pages
    return text



On 04/05/2017 07:37 PM, T Johnson wrote:
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 sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto: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