CREATE or REPLACE FUNCTION new_guid()
RETURNS "pg_catalog"."varchar" AS
$BODY$
DECLARE
v_seed_value varchar(32);
BEGIN
select
md5(
inet_client_addr()::varchar ||
timeofday() ||
inet_server_addr()::varchar ||
to_hex(inet_client_port())
)
into v_seed_value;
return (substr(v_seed_value,1,8) || '-' ||
substr(v_seed_value,9,4) || '-' ||
substr(v_seed_value,13,4) || '-' ||
substr(v_seed_value,17,4) || '-' ||
substr(v_seed_value,21,12));
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER;
用法:
SELECT new_guid();
-- 或剔除-
select replace(new_guid(),'-','')
标签:guid,postgresql,数据库,value,substr,seed,new,varchar,GUID From: https://blog.51cto.com/u_688107/5850785