How to get VARCHAR2 columns to use BYTE and not CHAR?
It looks like SQLAlchemy defaults to creating VARCHAR2
columns as CHAR
. How can I have it create with BYTE
instead?
from sqlalchemy import MetaData, Column, String from sqlalchemy.ext.declarative import declarative_base metadata = MetaData() Base = declarative_base(metadata=metadata) class Foo(Base): __tablename__ = 'foo' name = Column(String(10), primary_key=True) Foo.__table__.create(bind=engine)
This creates the following table:
CREATE TABLE XXMD.FOO ( NAME VARCHAR2(10 CHAR) NOT NULL )
Instead, I would like it to create the following:
CREATE TABLE XXMD.FOO ( NAME VARCHAR2(10 BYTE) NOT NULL )
感谢Mike Bayer:
from sqlalchemy.ext.compiler import compiles class VARCHAR2Byte(String): pass @compiles(VARCHAR2Byte) def compile_varchar2_byte(type_, compiler, **kw): len = type_.length return 'VARCHAR2(%i BYTE)' % len链接地址: http://www.djcxy.com/p/63436.html
上一篇: 了解Python中的repr()函数