Created
May 29, 2018 07:09
-
-
Save felipem775/59ec943d284821b9ebfe724a6e3246f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- original https://stackoverflow.com/a/19532132/2428230 | |
CREATE FUNCTION make_uid() RETURNS text AS $$ | |
DECLARE | |
new_uid text; | |
done bool; | |
BEGIN | |
done := false; | |
WHILE NOT done LOOP | |
new_uid := upper(substring(md5(''||now()::text||random()::text),1,8)); | |
done := NOT exists(SELECT 1 FROM report_users WHERE confirm_key=new_uid); | |
END LOOP; | |
RETURN new_uid; | |
END; | |
$$ LANGUAGE PLPGSQL VOLATILE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment