加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – create aggregate中的语法错误

发布时间:2020-12-13 15:50:01 所属栏目:百科 来源:网络整理
导读:尝试创建聚合函数: create aggregate min (my_type) ( sfunc = least,stype = my_type);ERROR: syntax error at or near "least"LINE 2: sfunc = least,^ 我错过了什么? Although the manual calls least a function: The GREATEST and LEAST functions s
尝试创建聚合函数:

create aggregate min (my_type) (
    sfunc = least,stype = my_type
);
ERROR:  syntax error at or near "least"
LINE 2:     sfunc = least,^

我错过了什么?

Although the manual calls least a function:

The GREATEST and LEAST functions select the largest or smallest value from a list of any number of expressions.

我找不到它了:

dfS least
                       List of functions
 Schema | Name | Result data type | Argument data types | Type 
--------+------+------------------+---------------------+------
(0 rows)

解决方法

至少和最伟大的不是真正的功能;在内部,它们被解析为MinMaxExpr(参见src / include / nodes / primnodes.h).

你可以使用这样的通用函数实现你想要的:

CREATE FUNCTION my_least(anyelement,anyelement) RETURNS anyelement
   LANGUAGE sql IMMUTABLE CALLED ON NULL INPUT
   AS 'SELECT LEAST($1,$2)';

(感谢Erwin Brandstetter关于CALLED ON NULL INPUT以及使用LEAST的想法.)

然后,您可以创建聚合

CREATE AGGREGATE min(my_type) (sfunc = my_least,stype = my_type);

这只适用于my_type的比较函数,否则你必须提出不同的my_least函数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读