当前位置: 首页>>代码示例>>Python>>正文


Python sqlalchemy.union_all方法代码示例

本文整理汇总了Python中sqlalchemy.union_all方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.union_all方法的具体用法?Python sqlalchemy.union_all怎么用?Python sqlalchemy.union_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy的用法示例。


在下文中一共展示了sqlalchemy.union_all方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_union_all_lightweight

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import union_all [as 别名]
def test_union_all_lightweight(self, connection):
        """like test_union_all, but breaks the sub-union into
        a subquery with an explicit column reference on the outside,
        more palatable to a wider variety of engines.

        """

        u = union(select([t1.c.col3]), select([t1.c.col3])).alias()

        e = union_all(select([t1.c.col3]), select([u.c.col3]))

        wanted = [("aaa",), ("aaa",), ("bbb",), ("bbb",), ("ccc",), ("ccc",)]
        found1 = self._fetchall_sorted(connection.execute(e))
        eq_(found1, wanted)

        found2 = self._fetchall_sorted(
            connection.execute(e.alias("foo").select())
        )
        eq_(found2, wanted) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_query.py

示例2: compile

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import union_all [as 别名]
def compile(self):
        def reduce_union(left, right, distincts=iter(self.distincts)):
            distinct = next(distincts)
            sa_func = sa.union if distinct else sa.union_all
            return sa_func(left, right)

        context = self.context
        selects = []

        for table in self.tables:
            table_set = context.get_compiled_expr(table)
            selects.append(table_set.cte().select())

        return functools.reduce(reduce_union, selects) 
开发者ID:ibis-project,项目名称:ibis,代码行数:16,代码来源:alchemy.py

示例3: test_union_all

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import union_all [as 别名]
def test_union_all(self, connection):
        e = union_all(
            select([t1.c.col3]),
            union(select([t1.c.col3]), select([t1.c.col3])),
        )

        wanted = [("aaa",), ("aaa",), ("bbb",), ("bbb",), ("ccc",), ("ccc",)]
        found1 = self._fetchall_sorted(connection.execute(e))
        eq_(found1, wanted)

        found2 = self._fetchall_sorted(
            connection.execute(e.alias("foo").select())
        )
        eq_(found2, wanted) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:16,代码来源:test_query.py

示例4: test_distinct

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import union_all [as 别名]
def test_distinct(self):
        Address, addresses, users, User = (
            self.classes.Address,
            self.tables.addresses,
            self.tables.users,
            self.classes.User,
        )

        # this is an involved 3x union of the users table to get a lot of rows.
        # then see if the "distinct" works its way out.  you actually get
        # the same result with or without the distinct, just via less or
        # more rows.
        u2 = users.alias("u2")
        s = sa.union_all(
            u2.select(use_labels=True),
            u2.select(use_labels=True),
            u2.select(use_labels=True),
        ).alias("u")

        mapper(
            User,
            users,
            properties={
                "addresses": relationship(
                    mapper(Address, addresses),
                    lazy="joined",
                    order_by=addresses.c.id,
                )
            },
        )

        sess = create_session()
        q = sess.query(User)

        def go():
            result = (
                q.filter(s.c.u2_id == User.id)
                .distinct()
                .order_by(User.id)
                .all()
            )
            eq_(self.static.user_address_result, result)

        self.assert_sql_count(testing.db, go, 1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:46,代码来源:test_eager_relations.py

示例5: test_distinct

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import union_all [as 别名]
def test_distinct(self):
        (
            users,
            items,
            order_items,
            orders,
            Item,
            User,
            Address,
            Order,
            addresses,
        ) = (
            self.tables.users,
            self.tables.items,
            self.tables.order_items,
            self.tables.orders,
            self.classes.Item,
            self.classes.User,
            self.classes.Address,
            self.classes.Order,
            self.tables.addresses,
        )

        mapper(Item, items)
        mapper(
            Order,
            orders,
            properties={
                "items": relationship(
                    Item, secondary=order_items, lazy="select"
                )
            },
        )
        mapper(
            User,
            users,
            properties={
                "addresses": relationship(
                    mapper(Address, addresses), lazy="select"
                ),
                "orders": relationship(Order, lazy="select"),
            },
        )

        sess = create_session()
        q = sess.query(User)

        # use a union all to get a lot of rows to join against
        u2 = users.alias("u2")
        s = sa.union_all(
            u2.select(use_labels=True),
            u2.select(use_labels=True),
            u2.select(use_labels=True),
        ).alias("u")
        result = (
            q.filter(s.c.u2_id == User.id).order_by(User.id).distinct().all()
        )
        eq_(self.static.user_all_result, result) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:60,代码来源:test_lazy_relations.py


注:本文中的sqlalchemy.union_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。