Not that it is a useful use case, but I believe that this is a bug that causes index corruption:
CREATE TABLE mytable( id integer PRIMARY KEY, id2 integer NOT NULL ); CREATE FUNCTION makeindex() RETURNS trigger LANGUAGE plpgsql AS $$BEGIN CREATE INDEX ON mytable(id2); RETURN NEW; END;$$; CREATE TRIGGER makeindex BEFORE INSERT ON mytable FOR EACH ROW EXECUTE PROCEDURE makeindex(); INSERT INTO mytable VALUES (1, 42); SELECT * FROM mytable; ┌────┬─────┐ │ id │ id2 │ ├────┼─────┤ │ 1 │ 42 │ └────┴─────┘ (1 row) But 42 is not present in the index: SET enable_seqscan = off; SELECT * FROM mytable WHERE id2 = 42; ┌────┬─────┐ │ id │ id2 │ ├────┼─────┤ └────┴─────┘ (0 rows) -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers