当你插入一行(PostgreSQL> = 9.5)时,你希望可能的INSERT和可能的UPDATE完全一样,你可以这样写: INSERT INTO tablename (id, username, password, level, email) VALUES (1, 'John', 'qwerty', 5, 'john@mail.com') ON CONFLICT (id) DO UPDATE SET id=EXCLUDED.id, username=EXCLUDED.username, password=EXCLUDED.password, level=EXCLUDED.level,email=EXCLUDED.email 有一个更短的路? 只是说:使用所有的EXCLUDE值。 在SQLite中,我曾经这样做过: INSERT OR REPLACE INTO tablename (id, user, password, level, email) VALUES (1, 'John', 'qwerty', 5, 'john@mail.com')