mysql 版本的 reddit pgsql 热度函数

发布于 2025-01-07 06:35:31 字数 817 浏览 0 评论 0原文

首先,我对我的英语感到抱歉,这是我在这里发表的第一篇文章,我的英语没有我希望的那么好,但我希望这足以得到答案。

那么,你们中的一些人现在可能如何将自己的源代码放到 github 上,而我想使用(一点点)由我修改)具有热度算法的 SQL 模式版本。问题是模式是用 psgsql 编写的,而我的数据库使用 mysql 引擎。

我尝试手动转换模式,但我放弃了,没有任何效果,所以我用杂项工具和应用程序再次尝试,但甚至没有一个支持过程和应用程序的转换。功能,问题是我只需要这一个选项。

那么,你们中的任何人都可以帮助我从那里转换热度函数:

create or replace function hot(ups integer, downs integer, date timestamp with time zone) returns numeric as $$
    select round(cast(log(greatest(abs($1 - $2), 1)) + sign($1 - $2) * (date_part('epoch', $3) - 1134028003) / 45000.0 as numeric), 7)
$$ language sql immutable;

对于mysql模式,我将非常感激:)

再次为我的语言感到抱歉,我现在低估了标准:)

Firstly sorry for my english, it's my first post here, and my english isn't as well as i wish but i hope it'll be enough to get a answer.

So how some of you maybe now reddit put their own source code on github and i want to use (a little modified by me) version of sql schema with a hotness algorithm. The problem is that schema is written in psgsql and my database use mysql engine.

I tried to convert schema manually but i give up with no effects, so i try again with misc tools and apps, but not even one of them support converting of procedures & functions, and the problem is that i need exactly just that one option.

So, is anyone of you can help me convert the hotness function from there:

create or replace function hot(ups integer, downs integer, date timestamp with time zone) returns numeric as $
    select round(cast(log(greatest(abs($1 - $2), 1)) + sign($1 - $2) * (date_part('epoch', $3) - 1134028003) / 45000.0 as numeric), 7)
$ language sql immutable;

to mysql schema, i would be very grateful :)

Once again sorry for my language, i now that i underestimates the standard :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想念有你 2025-01-14 06:35:31

我刚刚在下面写了这个函数,它似乎可以工作。

CREATE FUNCTION hot (ups INT(10),downs INT(10),d TIMESTAMP)
RETURNS DOUBLE DETERMINISTIC
RETURN ROUND(LOG(GREATEST(ABS(ups-downs), 1)) + SIGN(ups-downs)*(UNIX_TIMESTAMP(d) - 1134028003) / 45000.0,7);

我将其输出与 这段 Python 代码 的输出进行了比较,一切似乎都正常。

示例运行:

SELECT hot(20,10,'2013-01-01 00:00:00');

Query OK, 0 rows affected (0.00 sec)

+----------------------------------+
| hot(20,10,'2013-01-01 00:00:00') |
+----------------------------------+
|                     4957.1202962 |
+----------------------------------+
1 row in set (0.00 sec)

I just wrote this function below, and it seem to work.

CREATE FUNCTION hot (ups INT(10),downs INT(10),d TIMESTAMP)
RETURNS DOUBLE DETERMINISTIC
RETURN ROUND(LOG(GREATEST(ABS(ups-downs), 1)) + SIGN(ups-downs)*(UNIX_TIMESTAMP(d) - 1134028003) / 45000.0,7);

I compared its outputs to the outputs of this Python code, everything seem OK.

Sample run:

SELECT hot(20,10,'2013-01-01 00:00:00');

Query OK, 0 rows affected (0.00 sec)

+----------------------------------+
| hot(20,10,'2013-01-01 00:00:00') |
+----------------------------------+
|                     4957.1202962 |
+----------------------------------+
1 row in set (0.00 sec)
情话难免假 2025-01-14 06:35:31

我不知道用户定义函数的 MySQL 语法,但 PostgreSQL 的一些特定部分是:

date_part('epoch', $3)

自纪元以来的 $3 秒数,即自 1970-01-01 00:00:00 以来。

1134028003

从纪元到 2005-12-08 07:46:43 的秒数。

也许这对于查找 MySQL 的等效项很有用。

I don't know the MySQL syntax for user defined functions, but some PostgreSQL specific parts are:

date_part('epoch', $3)

Number of seconds of $3 since the epoch i.e. since 1970-01-01 00:00:00.

1134028003

Number of seconds from epoch to 2005-12-08 07:46:43.

Perhaps this is useful for finding MySQL equivalents.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文