Advertisement
rockdrilla

recursive ids

May 9th, 2017
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE mboxes (
  2.     id INTEGER NOT NULL,
  3.     -- ...
  4.     is_login_alias BOOLEAN DEFAULT FALSE NOT NULL,
  5.     parent_id INTEGER
  6. );
  7.  
  8. CREATE SEQUENCE seq_mboxes_id
  9.   START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
  10.  
  11. ALTER SEQUENCE seq_mboxes_id
  12.   OWNED BY mboxes.id;
  13.  
  14. ALTER TABLE mboxes
  15.   ALTER COLUMN id SET DEFAULT nextval('seq_mboxes_id'::regclass);
  16.  
  17. ALTER TABLE mboxes
  18.   ADD CONSTRAINT mboxes_pkey PRIMARY KEY (id);
  19.  
  20. ALTER TABLE mboxes
  21.   ADD CONSTRAINT mboxes_fkey_self
  22.   FOREIGN KEY (parent_id) REFERENCES mboxes(id) ON DELETE CASCADE;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement