如何在Postgres 9.0+中创建Windows格式的GUID?
我尝试了以下函数:
CREATE or REPLACE FUNCTION public.getguid() RETURNS 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;
来自
http://postgresql.1045698.n5.nabble.com/newid-in-postgres-td1879346.html
尝试过
select getguid()
union all
select getguid()
但它返回相同的值
"c41121ed-b6fb-c9a6-bc9b-574c82929e7e"
"c41121ed-b6fb-c9a6-bc9b-574c82929e7e"
如何修复这个问题,以便返回唯一的行?