CREATE OR REPLACE FUNCTION gen_uuid()
  RETURNS VARCHAR
AS '
BEGIN

  RETURN upper(cast(uuid_generate_v4() AS VARCHAR));

END;
' LANGUAGE plpgsql;
