Snowflake有一个名为LEAST的函数,该函数可以应用于两列,并返回每行的较低值。
在使用pypika构建SnowflakeQuery时,如何使用该函数?
发布于 2020-06-03 22:44:32
Pypika允许你在自己的默认功能列表中不提供define additional functions。
要在其中定义LEAST,可以使用以下形式,镜像也使用类似变量参数签名的pypika.functions.Concat:
class Least(Function):
def __init__(self, *terms, **kwargs):
super(Least, self).__init__('LEAST', *terms, **kwargs)示例用法:
>>> from pypika.functions import Function
>>> class Least(Function):
... def __init__(self, *terms, **kwargs):
... super(Least, self).__init__('LEAST', *terms, **kwargs)
...
>>> q = Query.from_(customers).select(
... customers.id,
... Least(3, 2, 1).as_('least_example'),
... )
>>> q
SELECT "id",LEAST(3,2,1) "least_example" FROM "customers"https://stackoverflow.com/questions/62172558
复制相似问题