Skip to content

Instantly share code, notes, and snippets.

@finwe
Created July 12, 2021 06:53
Show Gist options
  • Save finwe/5908d30a0c5e61ffd8e8d0fde78220a3 to your computer and use it in GitHub Desktop.
Save finwe/5908d30a0c5e61ffd8e8d0fde78220a3 to your computer and use it in GitHub Desktop.
PostgreSQL gen_random_uuid polyfill for <13
DO $_$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_proc WHERE proname = 'gen_random_uuid') THEN
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE FUNCTION gen_random_uuid()
RETURNS uuid
LANGUAGE sql
AS $$
SELECT uuid_generate_v4()
$$;
END IF;
END
$_$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment