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(),
  }),

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`),
  }),

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;
Was this page helpful?