PostgreSQL聚合函数超出范围

编程入门 行业动态 更新时间:2024-10-25 04:25:25
本文介绍了PostgreSQL聚合函数超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个函数,该函数将找到 tsrange 的交集,但是我无法使它起作用:

I am trying to create a function that will find the intersection of tsrange, but I can't get it work:

CREATE AGGREGATE intersection ( tsrange ) ( SFUNC = *, STYPE = tsrange )

推荐答案

对您的尝试有两个修改。首先,我认为您不能将运算符用作SFUNC,因此您需要定义一个命名函数来执行交集,并使用它。

There are two modifications to your attempt. First, I don't think you can use an operator as the SFUNC, so you need to define a named function to do the intersection, and use that.

CREATE or REPLACE FUNCTION int_tsrange(a tsrange, b tsrange) returns tsrange language plpgsql as 'begin return a * b; end';

第二,范围的默认值为空范围-因此,交集始终为空。您需要将范围初始化为无限范围’[,]’才能开始聚合。聚合定义如下所示:

Secondly, the default value for a range is the empty range -- so the intersection will always be empty. You need to initialize the range to an infinite range '[,]' to begin the aggregate. The aggregate definition then looks like:

CREATE AGGREGATE intersection ( tsrange ) ( SFUNC = int_tsrange, STYPE = tsrange, INITCOND = '[,]' );

更多推荐

PostgreSQL聚合函数超出范围

本文发布于:2023-10-16 12:16:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!