本文整理汇总了Python中sqlalchemy.func.rank方法的典型用法代码示例。如果您正苦于以下问题:Python func.rank方法的具体用法?Python func.rank怎么用?Python func.rank使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.func
的用法示例。
在下文中一共展示了func.rank方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: over
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def over(self, partition_by=None, order_by=None):
"""Produce an OVER clause against this filtered function.
Used against aggregate or so-called "window" functions,
for database backends that support window functions.
The expression::
func.rank().filter(MyClass.y > 5).over(order_by='x')
is shorthand for::
from sqlalchemy import over, funcfilter
over(funcfilter(func.rank(), MyClass.y > 5), order_by='x')
See :func:`~.expression.over` for a full description.
"""
return Over(self, partition_by=partition_by, order_by=order_by)
示例2: over
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def over(self, partition_by=None, order_by=None, range_=None, rows=None):
"""Produce an OVER clause against this filtered function.
Used against aggregate or so-called "window" functions,
for database backends that support window functions.
The expression::
func.rank().filter(MyClass.y > 5).over(order_by='x')
is shorthand for::
from sqlalchemy import over, funcfilter
over(funcfilter(func.rank(), MyClass.y > 5), order_by='x')
See :func:`_expression.over` for a full description.
"""
return Over(
self,
partition_by=partition_by,
order_by=order_by,
range_=range_,
rows=rows,
)
示例3: over
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def over(self, partition_by=None, order_by=None, range_=None, rows=None):
"""Produce an OVER clause against this filtered function.
Used against aggregate or so-called "window" functions,
for database backends that support window functions.
The expression::
func.rank().filter(MyClass.y > 5).over(order_by='x')
is shorthand for::
from sqlalchemy import over, funcfilter
over(funcfilter(func.rank(), MyClass.y > 5), order_by='x')
See :func:`~.expression.over` for a full description.
"""
return Over(
self, partition_by=partition_by, order_by=order_by,
range_=range_, rows=rows)
示例4: __init__
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def __init__(self, element, *order_by):
r"""Produce a :class:`.WithinGroup` object against a function.
Used against so-called "ordered set aggregate" and "hypothetical
set aggregate" functions, including :class:`.percentile_cont`,
:class:`.rank`, :class:`.dense_rank`, etc.
:func:`~.expression.within_group` is usually called using
the :meth:`.FunctionElement.within_group` method, e.g.::
from sqlalchemy import within_group
stmt = select([
department.c.id,
func.percentile_cont(0.5).within_group(
department.c.salary.desc()
)
])
The above statement would produce SQL similar to
``SELECT department.id, percentile_cont(0.5)
WITHIN GROUP (ORDER BY department.salary DESC)``.
:param element: a :class:`.FunctionElement` construct, typically
generated by :data:`~.expression.func`.
:param \*order_by: one or more column elements that will be used
as the ORDER BY clause of the WITHIN GROUP construct.
.. versionadded:: 1.1
.. seealso::
:data:`.expression.func`
:func:`.expression.over`
"""
self.element = element
if order_by is not None:
self.order_by = ClauseList(
*util.to_list(order_by),
_literal_as_text=_literal_as_label_reference)
示例5: __init__
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def __init__(self, element, *order_by):
r"""Produce a :class:`.WithinGroup` object against a function.
Used against so-called "ordered set aggregate" and "hypothetical
set aggregate" functions, including :class:`.percentile_cont`,
:class:`.rank`, :class:`.dense_rank`, etc.
:func:`_expression.within_group` is usually called using
the :meth:`.FunctionElement.within_group` method, e.g.::
from sqlalchemy import within_group
stmt = select([
department.c.id,
func.percentile_cont(0.5).within_group(
department.c.salary.desc()
)
])
The above statement would produce SQL similar to
``SELECT department.id, percentile_cont(0.5)
WITHIN GROUP (ORDER BY department.salary DESC)``.
:param element: a :class:`.FunctionElement` construct, typically
generated by :data:`~.expression.func`.
:param \*order_by: one or more column elements that will be used
as the ORDER BY clause of the WITHIN GROUP construct.
.. versionadded:: 1.1
.. seealso::
:data:`.expression.func`
:func:`_expression.over`
"""
self.element = element
if order_by is not None:
self.order_by = ClauseList(
*util.to_list(order_by), _literal_as_text_role=roles.ByOfRole
)
示例6: test_no_paren_fns
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def test_no_paren_fns(self):
for fn, expected in [
(func.uid(), "uid"),
(func.UID(), "UID"),
(func.sysdate(), "sysdate"),
(func.row_number(), "row_number()"),
(func.rank(), "rank()"),
(func.now(), "CURRENT_TIMESTAMP"),
(func.current_timestamp(), "CURRENT_TIMESTAMP"),
(func.user(), "USER"),
]:
self.assert_compile(fn, expected)
示例7: test_funcfilter_windowing_orderby
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def test_funcfilter_windowing_orderby(self):
# test filtered windowing:
self.assert_compile(
select(
[
func.rank()
.filter(table1.c.name > "foo")
.over(order_by=table1.c.name)
]
),
"SELECT rank() FILTER (WHERE mytable.name > :name_1) "
"OVER (ORDER BY mytable.name) AS anon_1 FROM mytable",
)
示例8: test_funcfilter_windowing_orderby_partitionby
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def test_funcfilter_windowing_orderby_partitionby(self):
self.assert_compile(
select(
[
func.rank()
.filter(table1.c.name > "foo")
.over(order_by=table1.c.name, partition_by=["description"])
]
),
"SELECT rank() FILTER (WHERE mytable.name > :name_1) "
"OVER (PARTITION BY mytable.description ORDER BY mytable.name) "
"AS anon_1 FROM mytable",
)
示例9: test_funcfilter_windowing_rows
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import rank [as 别名]
def test_funcfilter_windowing_rows(self):
self.assert_compile(
select(
[
func.rank()
.filter(table1.c.name > "foo")
.over(rows=(1, 5), partition_by=["description"])
]
),
"SELECT rank() FILTER (WHERE mytable.name > :name_1) "
"OVER (PARTITION BY mytable.description ROWS BETWEEN :param_1 "
"FOLLOWING AND :param_2 FOLLOWING) "
"AS anon_1 FROM mytable",
)