GaussDB-HashFunc函数
-
bucketabstime(value,flag)
描述:对abstime格式的数值value计算hash值并找到对应的hashbucket桶。
参数:value为需要转换的数值,类型为abstime,flag为int类型表示数据分布方式,0表示hash分布。
返回值类型:int32
示例:
| ``` gaussdb=# SELECT bucketabstime('2011-10-01 10:10:10.112',1); bucketabstime --------------- 13954 (1 row)
| --------------------------------------------------------------------------------------------------------------------------- | -
bucketbool(value,flag)
描述:对bool格式的数值value计算hash值并找到对应的hashbucket桶。
参数:value为需要转换的数值,类型为bool,flag为int类型表示数据分布方式,0表示hash分布。
返回值类型:int32
示例:
| ``` gaussdb=# SELECT bucketbool(true,1); bucketbool ------------ 1 (1 row) gaussdb=# SELECT bucketbool(false,1); bucketbool ------------ 0 (1 row)
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -
bucketbpchar(value, flag)
描述:对bpchar格式的数值value计算hash值并找到对应的hashbucket桶。
参数:value为需要转换的数值,类型为bpchar,flag为int类型表示数据分布方式,0表示hash分布。
返回值类型:int32
示例:
| ``` gaussdb=# SELECT bucketbpchar('test',1); bucketbpchar -------------- 9761 (1 row)
| ---------------------------------------------------------------------------------------------------- |
-
bucketbytea(value,flag)
描述:对bytea格式的数值value计算hash值并找到对应的hashbucket桶。
参数:value为需要转换的数值,类型为bytea,flag为int类型表示数据分布方式,0表示hash分布。
返回值类型:int32
示例:
| ``` gaussdb=# SELECT bucketbytea('test',1); bucketbytea ------------- 9761 (1 row)
| ------------------------------------------------------------------------------------------------ |
-
bucketcash(value,flag)
描述:对money格式的数值value计算hash值并找到对应的hashbucket桶。
参数:value为需要转换的数值,类型为money,flag为int类型表示数据分布方式,0表示hash分布。
返回值类型:int32
示例:
| ``` gaussdb=# SELECT bucketcash(10::money,1); bucketcash ------------ 8468 (1 row)
| ----------------------------------------------------------------------------------------------- | -
getbucket(value,flag)
value为需要输入的数值,类型:
“char”,abstime,bigint,boolean,bytea,character varying,character,date,double precision,int2vector,integer,interval,money,name,numeric,nvarchar2,oid,oidvector,raw,real,record,reltime,smalldatetime,smallint,text,time with time zone,time without time zone,timestamp with time zone,timestamp without time zone,tinyint,uuid。
flag表示数据分布方式,类型:integer
返回值类型:integer
示例:
| ``` gaussdb=# SELECT getbucket(10,'H'); getbucket ----------- 14535 (1 row) gaussdb=# SELECT getbucket(11,'H'); getbucket ----------- 13449 (1 row) gaussdb=# SELECT getbucket(11,'R'); getbucket ----------- 13449 (1 row) gaussdb=# SELECT getbucket(12,'R'); getbucket ----------- 9412 (1 row)
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -
ora_hash(expression,[seed])
描述:用于计算给定表达式的哈希值。expression:可输入的类型覆盖字符串,时间类型,数字类型,根据expression进行计算哈希值。seed:可选参数,一个int8值,可以对同一个输入值返回不同的结果, 用于计算带随机数的hash值。
返回类型:int8类型的哈希值。
示例:
| ``` 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
示例:
| ``` gaussdb=# SELECT hash_array(ARRAY[[1,2,3],[1,2,3]]); hash_array ------------ -382888479 (1 row)
| ----------------------------------------------------------------------------------------------------------- | -
hash_numeric(numeric)
参数:Numeric类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# SELECT hash_numeric(30); hash_numeric -------------- -282860963 (1 row)
| ----------------------------------------------------------------------------------------------- | -
hash_range(anyrange)
参数:anyrange类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# SELECT hash_range(numrange(1.1,2.2)); hash_range ------------ 683508754 (1 row)
| ------------------------------------------------------------------------------------------------------ | -
hashbpchar(character)
参数:character类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# SELECT hashbpchar('hello'); hashbpchar ------------- -1870292951 (1 row)
| ----------------------------------------------------------------------------------------------- | -
hashchar(char)
参数:char类型的数据或者bool类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# SELECT hashbpchar('hello'); hashbpchar ------------- -1870292951 (1 row) gaussdb=# SELECT hashchar('true'); hashchar ------------ 1686226652 (1 row)
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -
hashenum(anyenum)
参数:anyenum类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# CREATE TYPE b1 AS ENUM('good', 'bad', 'ugly'); CREATE TYPE gaussdb=# call hashenum('good'::b1); hashenum ------------ 1821213359 (1 row)
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -
hashfloat4(real)
参数:real类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# SELECT hashfloat4(12.1234); hashfloat4 ------------ 1398514061 (1 row)
| -------------------------------------------------------------------------------------------- | -
hashfloat8(double precision)
参数:double precision类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# SELECT hashfloat8(123456.1234); hashfloat8 ------------ 1673665593 (1 row)
| ------------------------------------------------------------------------------------------------ | -
hashinet(inet)
参数:inet类型的数据。
返回值类型:integer
示例:
| ``` gaussdb=# SELECT hashinet('127.0.0.1'::inet); hashinet ------------- -1435793109 (1 row)
| ------------------------------------------------------------------------------------------------------- | -
hashint1(tinyint)
参数:tinyint类型的数据。
返回值类型:uint32
示例:
| ``` gaussdb=# SELECT hashint1(20); hashint1 ------------- -2014641093 (1 row)
| ---------------------------------------------------------------------------------------- | -
hashint2(smallint)
参数:smallint类型的数据。
返回值类型:uint32
示例:
gaussdb=# SELECT hashint2(20000); hashint2 ------------ -863179081 (1 row) -
bucketchar()
参数:char, integer
返回值类型:integer
-
bucketdate()
参数:date, integer
返回值类型:integer
-
bucketfloat4()
参数:real, integer
返回值类型:integer
-
bucketfloat8()
参数:double precision, integer
返回值类型:integer
-
bucketint1()
参数:tinyint, integer
返回值类型:integer
-
bucketint2()
参数:smallint, integer
返回值类型:integer
-
bucketint2vector()
参数:int2vector, integer
返回值类型:integer
-
bucketint4()
参数:integer, integer
返回值类型:integer
-
bucketint8()
参数:bigint, integer
返回值类型:integer
-
bucketinterval()
参数:interval, integer
返回值类型:integer
-
bucketname()
参数:name, integer
返回值类型:integer
-
bucketnumeric()
参数:numeric, integer
返回值类型:integer
-
bucketnvarchar2()
参数:nvarchar2, integer
返回值类型:integer
-
bucketoid()
参数:oid, integer
返回值类型:integer
-
bucketoidvector()
参数:oidvector, integer
返回值类型:integer
-
bucketraw()
参数:raw, integer
返回值类型:integer
-
bucketreltime()
参数:reltime, integer
返回值类型:integer
-
bucketsmalldatetime()
参数:smalldatetime, integer
返回值类型:integer
-
buckettext()
参数:text, integer
返回值类型:integer
-
buckettime()
参数:time without time zone, integer
返回值类型:integer
-
buckettimestamp()
参数:timestamp without time zone, integer
返回值类型:integer
-
buckettimestamptz()
参数:timestamp with time zone, integer
返回值类型:integer
-
buckettimetz()
参数:time with time zone, integer
返回值类型:integer
-
bucketuuid()
参数:uuid, integer
返回值类型:integer
-
bucketvarchar()
参数:character varying, integer
返回值类型:integer
更多详情请参考GaussDB 文档中心:doc.hcs.huawei.com/db/zh-cn/ga…