云数据库 GaussDB-HashFunc函数
HashFunc函数
- ora_hash(expression,[seed])
描述:用于计算给定表达式的哈希值。expression:可输入的类型覆盖字符串,时间类型,数字类型,根据expression进行计算哈希值。seed:可选参数,一个int8值,可以对同一个输入值返回不同的结果, 用于计算带随机数的hash值。
返回类型:int8类型的哈希值。
示例:
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940
gaussdb=# select ora_hash(123); ora_hash ------------ 4089882933(1 row)gaussdb=# select ora_hash('123'); ora_hash ------------ 2034089965(1 row)gaussdb=# select ora_hash('sample'); ora_hash ------------ 1573005290(1 row)gaussdb=# select ora_hash(to_date('2012-1-2','yyyy-mm-dd')); ora_hash ------------ 1171473495(1 row)gaussdb=# select ora_hash(123,234); ora_hash ------------ -9089505052966355682(1 row)gaussdb=# select ora_hash('123',234); ora_hash ------------ 5742589019960764616(1 row)gaussdb=# select ora_hash('sample',234); ora_hash ------------ -1747984408055821656(1 row)gaussdb=# select ora_hash(to_date('2012-1-2','yyyy-mm-dd'),234); ora_hash ------------ -3306025179710572679(1 row)
此函数在参数a_format_version值为10c和a_format_dev_version值为s2的情况下才能生效。
- hash_array(anyarray)
描述:数组哈希,将数组的元素通过哈希函数得到结果,并返回合并结果。
参数:数据类型为anyarray。
返回值类型:integer
示例:
12345
gaussdb=# select hash_array(ARRAY[[1,2,3],[1,2,3]]); hash_array ------------ -382888479(1 row)
- hash_group(key)
描述:流引擎(由于规格变更,当前版本已经不再支持本特性,请不要使用)中,该函数可将Group Clause中的各列计算为一个hash值。
参数:key为Group Clause中各列的值。
返回值类型:32位hash值
示例:
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031
按照步骤依次执行。gaussdb=# CREATE TABLE tt(a int, b int,c int,d int);CREATE TABLEgaussdb=# select * from tt; a | b | c | d ---+---+---+---(0 rows)gaussdb=# insert into tt values(1,2,3,4);INSERT 0 1gaussdb=# select * from tt; a | b | c | d ---+---+---+--- 1 | 2 | 3 | 4(1 row)gaussdb=# insert into tt values(5,6,7,8);INSERT 0 1gaussdb=# select * from tt; a | b | c | d ---+---+---+--- 1 | 2 | 3 | 4 5 | 6 | 7 | 8(2 rows)gaussdb=# select hash_group(a,b) from tt where a=1 and b=2; hash_group ------------ 990882385(1 row)
- hash_numeric(numeric)
参数:Numeric类型的数据。
返回值类型:integer
示例:
12345
gaussdb=# select hash_numeric(30); hash_numeric -------------- -282860963(1 row)
- hash_range(anyrange)
参数:anyrange类型的数据。
返回值类型:integer
示例:
12345
gaussdb=# select hash_range(numrange(1.1,2.2)); hash_range ------------ 683508754(1 row)
- hashbpchar(character)
参数:character类型的数据。
返回值类型:integer
示例:
12345
gaussdb=# select hashbpchar('hello'); hashbpchar ------------- -1870292951(1 row)
- hashchar(char)
参数:char类型的数据或者bool类型的数据。
返回值类型:integer
示例:
1 2 3 4 5 6 7 8 91011
gaussdb=# select hashbpchar('hello'); hashbpchar ------------- -1870292951(1 row)gaussdb=# select hashchar('true'); hashchar ------------ 1686226652(1 row)
- hashenum(anyenum)
参数:anyenum类型的数据。
返回值类型:integer
示例:
1234567
gaussdb=# CREATE TYPE b1 AS ENUM('good', 'bad', 'ugly');CREATE TYPEgaussdb=# call hashenum('good'::b1); hashenum ------------ 1821213359(1 row)
- hashfloat4(real)
参数:real类型的数据。
返回值类型:integer
示例:
12345
gaussdb=# select hashfloat4(12.1234); hashfloat4 ------------ 1398514061(1 row)
- hashfloat8(double precision)
参数:double precision类型的数据。
返回值类型:integer
示例:
12345
gaussdb=# select hashfloat8(123456.1234); hashfloat8 ------------ 1673665593(1 row)
- hashinet(inet)
描述:支持inet / cidr上的哈希索引的功能。返回传入inet的hash值。
参数:inet类型的数据。
返回值类型:integer
示例:
12345
gaussdb=# select hashinet('127.0.0.1'::inet); hashinet ------------- -1435793109(1 row)
- hashint1(tinyint)
参数:tinyint类型的数据。
返回值类型:uint32
示例:
12345
gaussdb=# select hashint1(20); hashint1 ------------- -2014641093(1 row)
- hashint2(smallint)
参数:smallint类型的数据。
返回值类型:uint32
示例:
gaussdb=# select hashint2(20000); hashint2 ------------ -863179081(1 row)
- GaussDB函数_GaussDB数据库函数_高斯数据库函数_华为云
- 调用函数_函数调用方式_函数工作流 FunctionGraph-华为云
- GaussDB支持的函数_GaussDB函数类型解析_高斯数据库支持的函数-华为云
- GaussDB数据库函数_GaussDB函数和操作符_高斯数据库函数-华为云
- GaussDB数据库函数和字符串_高斯数据库优势_新建高斯数据库_高斯协议
- GaussDB数据库函数_GaussDB介绍_高斯数据库函数
- 使用容器镜像部署函数_函数部署_函数工作流 FunctionGraph-华为云
- 如何使用模板创建函数_模板创建函数_函数工作流 FunctionGraph-华为云
- 什么是函数工作流_函数托管计算服务_函数工作流 FunctionGraph-华为云
- 使用SpringBoot构建HTTP函数_functiongraph_函数工作流