Guest User

Untitled

a guest
Nov 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. drop table if exists users;
  2. create table users (
  3. id serial primary key,
  4. email varchar(255) not null check(strpos(email, '@') > 0),
  5. password varchar(255) not null check(password <> '')
  6. --, unique (lower(email)) не будет работать
  7. );
  8. create unique index email_unique_idx on users (lower(email));
  9. insert into users (email, password) values ('test@mail.com', 'test123'), ('TEST@mail.com', 'qweasd');
  10. -- ERROR: duplicate key value violates unique constraint "email_unique_idx"
  11. -- DETAIL: Key (lower(email::text))=(test@mail.com) already exists.
  12. -- SQL state: 23505
Add Comment
Please, Sign In to add comment