Because sometimes faking it is enough.
Last active
July 27, 2016 21:51
-
-
Save tifletcher/ec68eb48b766fb25b066655c41e36596 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function genGUID() { | |
// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16); | |
}); | |
} |
This file contains hidden or 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
-- postgres, at least | |
CREATE FUNCTION generate_uuid() RETURNS uuid AS $$ | |
SELECT md5(random()::text || clock_timestamp()::text)::uuid | |
$$ LANGUAGE SQL; | |
-- or, simpler: | |
create extension if not exists pgcrypto; | |
select gen_random_uuid() from foo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/12505158/generating-a-uuid-in-postgres-for-insert-statement