CREATE TABLE users ( id CHAR(22) NOT NULL PRIMARY KEY, username TEXT NOT NULL, host TEXT, display_name TEXT ); CREATE UNIQUE INDEX u_username_host ON users (username, host); CREATE UNIQUE INDEX u_username_local ON users (username) WHERE host IS NULL;