title: How to create guid in PostgreSQL
body: <p>How to create GUID in Windows format in Postgres 9.0+?</p>
  
  <p>I tried function </p>
  
  <pre><code>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;
  </code></pre>
  
  <p>from </p>
  
  <p><a href="http://postgresql.1045698.n5.nabble.com/newid-in-postgres-td1879346.html" rel="noreferrer">http://postgresql.1045698.n5.nabble.com/newid-in-postgres-td1879346.html</a></p>
  
  <p>Tried</p>
  
  <pre><code>select getguid()
  union all
  select getguid()
  </code></pre>
  
  <p>but it returns same values</p>
  
  <pre><code>"c41121ed-b6fb-c9a6-bc9b-574c82929e7e"
  "c41121ed-b6fb-c9a6-bc9b-574c82929e7e"
  </code></pre>
  
  <p>How to fix this so that unique rows are returned?</p>