用Python写了一个postgresql函数,感觉很爽 

CREATE LANGUAGE plpythonu; 


postgresql函数

CREATE OR REPLACE FUNCTION myfun1(text)
  RETURNS text AS
$BODY$
s = args[0]
h = 0;
n = len(s);
for i, c in enumerate(s):
        h = h + ord(c)*31**(n-1-i);
bits = 4*8;
return (h + 2**(bits-1)) % 2**bits - 2**(bits-1)        


$BODY$
  LANGUAGE 'plpythonu';

调用:返回字符串的hashcode值
  select myfun1('测试'),myfun1('a'),myfun1('A')



上述代码在MAC 笔记本上运行成功

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2021-12-19
  • 2021-07-26
  • 2021-12-02
猜你喜欢
  • 2022-12-23
  • 2021-04-13
  • 2021-10-29
  • 2022-02-03
  • 2021-11-01
  • 2021-10-17
  • 2022-12-23
相关资源
相似解决方案