Skip to content

Instantly share code, notes, and snippets.

@andrewfinnell
Last active August 19, 2016 21:22
Show Gist options
  • Select an option

  • Save andrewfinnell/c92d08136b1f7ce7a892cb297a510d05 to your computer and use it in GitHub Desktop.

Select an option

Save andrewfinnell/c92d08136b1f7ce7a892cb297a510d05 to your computer and use it in GitHub Desktop.
Postgres Table with UUID Primary key
-- Turn on the pgcrypto extension which should be installed
-- by default in recent Postgres builds.
CREATE EXTENSION pgcrypto;
-- Create a table with the primary key as an UUID
-- using the gen_random_uuid() function which is
-- available through the pgcrypto extension.
CREATE TABLE tbl_sometable
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
name text,
tags text,
CONSTRAINT tbl_sometable_pkey PRIMARY KEY (id)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment