當前位置: 首頁>>代碼示例>>Python>>正文


Python sqlalchemy.DECIMAL屬性代碼示例

本文整理匯總了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)),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:35,代碼來源:test_sequence.py

示例2: test_decimal_plain

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import DECIMAL [as 別名]
def test_decimal_plain(self):
        self.assert_compile(types.DECIMAL(), "DECIMAL") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:4,代碼來源:test_types.py

示例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)") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:4,代碼來源:test_types.py

示例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)") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:4,代碼來源:test_types.py

示例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) 
開發者ID:mxmzdlv,項目名稱:pybigquery,代碼行數:33,代碼來源:test_sqlalchemy_bigquery.py

示例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) 
開發者ID:streamsets,項目名稱:datacollector-tests,代碼行數:63,代碼來源:test_jdbc_stages.py


注:本文中的sqlalchemy.DECIMAL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。