Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. CREATE TABLE todos (
  2. id SERIAL PRIMARY KEY,
  3. title VARCHAR(255) NOT NULL,
  4. details TEXT NULL,
  5. priority INTEGER NOT NULL DEFAULT '1',
  6. created_at TIMESTAMP NOT NULL,
  7. completed_at TIMESTAMP NULL
  8. );
  9.  
  10.  
  11.  
  12.  
  13.  
  14. INSERT INTO todos
  15. (title, details, priority, created_at, completed_at)
  16. VALUES
  17. ('wash car', 'clean this nice car', '1', current_timestamp, current_timestamp),
  18. ('walk dog', 'walk the bulldog', '3', current_timestamp, NULL),
  19. ('clean house', 'clean the whole thing', '4', current_timestamp, NULL),
  20. ('buy groceries', 'get healthy food', '5', current_timestamp, NULL),
  21. ('change oil', 'go to jiffy lube', '2', current_timestamp, NULL);
  22.  
  23. select * from todos;
  24.  
  25. SELECT * FROM todos WHERE completed_at IS NULL;
  26.  
  27. SELECT * FROM todos WHERE priority > 1;
  28.  
  29. UPDATE todos SET completed_at = current_timestamp WHERE priority = 4;
  30.  
  31. select * from todos;
  32.  
  33. DELETE FROM todos WHERE completed_at IS NOT NULL;
  34.  
  35. select * from todos;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement