怎么在oracle分区上建表,如何在SQLAlchemy中创建分区Oracle表?

这是一个更好的答案,感谢Mike Byerfrom sqlalchemy import MetaData, Column, String, create_engine

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.schema import CreateTable

from sqlalchemy.ext.compiler import compiles

import textwrap

@compiles(CreateTable, "oracle")

def _add_suffixes(element, compiler, **kw):

text = compiler.visit_create_table(element, **kw)

if "oracle_partition" in element.element.info:

text += textwrap.dedent(

element.element.info["oracle_partition"]).strip()

return text

# use mock strategy just to illustrate this w/o my getting

# on an oracle box

def execute_sql(stmt):

print stmt.compile(dialect=engine.dialect)

engine = create_engine("oracle://", execute_sql, strategy="mock")

metadata = MetaData()

Base = declarative_base(metadata=metadata)

class Foo(Base):

__tablename__ = 'foo'

name = Column(String(10), primary_key=True)

__table_args__ = {

'info': {

'oracle_partition': """

PARTITION BY HASH(name)

( PARTITION p1 TABLESPACE tbs1

, PARTITION p2 TABLESPACE tbs2

, PARTITION p3 TABLESPACE tbs3

, PARTITION p4 TABLESPACE tbs4

)

"""

}

}

Foo.__table__.create(bind=engine)

使用经典:

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值