PG本身是不支持無(wú)符號(hào)整型的,可能是因?yàn)檫@個(gè)不屬于SQL標(biāo)準(zhǔn)的內(nèi)容,可以做癣朗,但沒(méi)必要~
但是近期開(kāi)發(fā)工具的時(shí)候,需要在SQL應(yīng)用層面旺罢,能將int類型轉(zhuǎn)換為unsigned int旷余,因此琢磨了一下,開(kāi)發(fā)了個(gè)工具函數(shù)扁达,純SQL實(shí)現(xiàn)(plpgsql)正卧,使用純SQL是因?yàn)椴幌霠砍毒幾g或者環(huán)境配置之類的事情,不然用C的話就是1行代碼的事兒罩驻。函數(shù)地址:PG小工具
使用效果如下:
postgres=# select hashint4(12345);
hashint4
-----------
-78097827
(1 row)
postgres=# select to_uint32(-78097827);
to_uint32
------------
4216869469
(1 row)
postgres=# select to_uint32(0);
to_uint32
-----------
0
(1 row)
postgres=# select to_uint32(12345);
to_uint32
-----------
12345
(1 row)
在GDB里面驗(yàn)證一下結(jié)果是不是OK
(gdb) p (uint32)(-78097827)
$1 = 4216869469
(gdb) quit