How can I create a `nulls not distinct` index in Postgres 15 for `push`?

Hi 👋 I'm having trouble to create such an index. This
(table) => ({
uniqueIdx: unique("mytable_uniq_idx_composite").on(table.foo, table.bar).nullsNotDistinct(),
}),
(table) => ({
uniqueIdx: unique("mytable_uniq_idx_composite").on(table.foo, table.bar).nullsNotDistinct(),
}),
somehow does not create an index that has the nulls not distinct constraint. Whereas a query like this would work.
(table) => ({
uniqueIdx: uniqueIndex('mytable_uniq_idx_composite')
.on(table.foo, table.bar)
.where(sql`NULLS NOT DISTINCT`),
}),
(table) => ({
uniqueIdx: uniqueIndex('mytable_uniq_idx_composite')
.on(table.foo, table.bar)
.where(sql`NULLS NOT DISTINCT`),
}),
However, there's a WHERE clause that breaks it.
CREATE UNIQUE INDEX IF NOT EXISTS "mytable_uniq_idx_composite" ON "mytable" USING btree ("foo","bar") WHERE NULLS NOT DISTINCT;
CREATE UNIQUE INDEX IF NOT EXISTS "mytable_uniq_idx_composite" ON "mytable" USING btree ("foo","bar") WHERE NULLS NOT DISTINCT;
1 Reply
Mario564
Mario564•6mo ago
@Michael Schaufelberger Hi there. Haven't seen this issue before, so it might be a bug we need to patch. Could you file an issue on the Github repo so we can keep track of this bug?

Did you find this page helpful?