mysql 版本的 reddit pgsql 热度函数
首先,我对我的英语感到抱歉,这是我在这里发表的第一篇文章,我的英语没有我希望的那么好,但我希望这足以得到答案。
那么,你们中的一些人现在可能如何将自己的源代码放到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在下面写了这个函数,它似乎可以工作。
我将其输出与 这段 Python 代码 的输出进行了比较,一切似乎都正常。
示例运行:
I just wrote this function below, and it seem to work.
I compared its outputs to the outputs of this Python code, everything seem OK.
Sample run:
我不知道用户定义函数的 MySQL 语法,但 PostgreSQL 的一些特定部分是:
自纪元以来的
$3
秒数,即自 1970-01-01 00:00:00 以来。从纪元到 2005-12-08 07:46:43 的秒数。
也许这对于查找 MySQL 的等效项很有用。
I don't know the MySQL syntax for user defined functions, but some PostgreSQL specific parts are:
Number of seconds of
$3
since the epoch i.e. since 1970-01-01 00:00:00.Number of seconds from epoch to 2005-12-08 07:46:43.
Perhaps this is useful for finding MySQL equivalents.