本文整理汇总了Python中sqlalchemy.DECIMAL属性的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.DECIMAL属性的具体用法?Python sqlalchemy.DECIMAL怎么用?Python sqlalchemy.DECIMAL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.DECIMAL属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: define_tables
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DECIMAL [as 别名]
def define_tables(cls, metadata):
Table(
"int_seq_t",
metadata,
Column("id", Integer, default=Sequence("int_seq")),
Column("txt", String(50)),
)
Table(
"bigint_seq_t",
metadata,
Column(
"id",
BIGINT,
default=Sequence(
"bigint_seq", data_type=BIGINT, start=3000000000
),
),
Column("txt", String(50)),
)
Table(
"decimal_seq_t",
metadata,
Column(
"id",
DECIMAL(10, 0),
default=Sequence(
"decimal_seq", data_type=DECIMAL(10, 0), start=3000000000,
),
),
Column("txt", String(50)),
)
示例2: test_decimal_plain
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DECIMAL [as 别名]
def test_decimal_plain(self):
self.assert_compile(types.DECIMAL(), "DECIMAL")
示例3: test_decimal_precision
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DECIMAL [as 别名]
def test_decimal_precision(self):
self.assert_compile(types.DECIMAL(2), "DECIMAL(2)")
示例4: test_decimal_scale
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DECIMAL [as 别名]
def test_decimal_scale(self):
self.assert_compile(types.DECIMAL(2, 4), "DECIMAL(2, 4)")
示例5: test_create_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DECIMAL [as 别名]
def test_create_table(engine):
meta = MetaData()
table = Table(
'test_pybigquery.test_table_create', meta,
Column('integer_c', sqlalchemy.Integer, doc="column description"),
Column('float_c', sqlalchemy.Float),
Column('decimal_c', sqlalchemy.DECIMAL),
Column('string_c', sqlalchemy.String),
Column('text_c', sqlalchemy.Text),
Column('boolean_c', sqlalchemy.Boolean),
Column('timestamp_c', sqlalchemy.TIMESTAMP),
Column('datetime_c', sqlalchemy.DATETIME),
Column('date_c', sqlalchemy.DATE),
Column('time_c', sqlalchemy.TIME),
Column('binary_c', sqlalchemy.BINARY),
bigquery_description="test table description",
bigquery_friendly_name="test table name"
)
meta.create_all(engine)
meta.drop_all(engine)
# Test creating tables with declarative_base
Base = declarative_base()
class TableTest(Base):
__tablename__ = 'test_pybigquery.test_table_create2'
integer_c = Column(sqlalchemy.Integer, primary_key=True)
float_c = Column(sqlalchemy.Float)
Base.metadata.create_all(engine)
Base.metadata.drop_all(engine)
示例6: test_mssql_producer_bigdecimal
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import DECIMAL [as 别名]
def test_mssql_producer_bigdecimal(sdc_builder, sdc_executor, database):
"""
Insert a Decimal value with up to 38 decimals into a Float column in MSSQL.
This will look like:
dev_data_generator >> jdbc_producer
"""
table_name = get_random_string(string.ascii_lowercase, 20)
table = sqlalchemy.Table(
table_name,
sqlalchemy.MetaData(),
sqlalchemy.Column('a_value', sqlalchemy.Float()),
sqlalchemy.Column('b_value', sqlalchemy.Float()),
sqlalchemy.Column('c_value', sqlalchemy.Float()),
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True, autoincrement=False)
)
table.create(database.engine)
pipeline_builder = sdc_builder.get_pipeline_builder()
dev_data_generator = pipeline_builder.add_stage('Dev Data Generator')
dev_data_generator.fields_to_generate = [{'field': 'id', 'type': 'INTEGER'},
{'field': 'a_value', 'precision': 50, 'scale': 40, 'type': 'DECIMAL'},
{'field': 'b_value', 'precision': 5, 'scale': 2, 'type': 'DECIMAL'},
{'field': 'c_value', 'type': 'DECIMAL'}]
dev_data_generator.batch_size = 1
FIELD_MAPPINGS = [dict(field='/id', columnName='id'),
dict(field='/a_value', columnName='a_value'),
dict(field='/b_value', columnName='b_value'),
dict(field='/c_value', columnName='c_value')]
jdbc_producer = pipeline_builder.add_stage('JDBC Producer')
jdbc_producer.set_attributes(default_operation='INSERT',
table_name=table_name,
field_to_column_mapping=FIELD_MAPPINGS,
stage_on_record_error='STOP_PIPELINE')
dev_data_generator >> jdbc_producer
pipeline = pipeline_builder.build('MSSQL BigDecimal')
sdc_executor.add_pipeline(pipeline.configure_for_environment(database))
try:
snapshot = sdc_executor.capture_snapshot(pipeline, start_pipeline=True, wait=True).snapshot
sdc_executor.stop_pipeline(pipeline)
records = [record.field for record in snapshot[dev_data_generator.instance_name].output]
result = database.engine.execute(table.select())
data_from_database = sorted(result.fetchall(), key=lambda row: row[0]) # order by id
result.close()
assert len(data_from_database) == 1
assert math.isclose(float(str(records[0]['a_value'])), data_from_database[0][0], rel_tol=0.02)
assert math.isclose(float(str(records[0]['b_value'])), data_from_database[0][1], rel_tol=0.02)
assert math.isclose(float(str(records[0]['c_value'])), data_from_database[0][2], rel_tol=0.02)
assert math.isclose(float(str(records[0]['id'])), data_from_database[0][3], rel_tol=0.02)
finally:
logger.info('Dropping table %s in %s database ...', table_name, database.type)
table.drop(database.engine)