Hi we have a table named billing_infos , where a partial index is created on three fields,account_id
, state_id
and deleted_at
where deleted_at
is NULL
,
My expectation is insert operation should fail on trying to insert duplicate values for account_id
, state_id
, deleted_at = null
.
But it seems it is creating another entry with duplicates. Is there any caveat with partial index when we check with null condition , I have gone through official documentation but couldn't find one, below is the snippet for my table schema
porterbizz=> \d+ application.billing_infos; Table
"application.billing_infos"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
-----------------+-----------------------------+-----------+----------+-------------------------------------------------------+----------+--------------+-------------
id | integer | | not null | nextval('application.billing_infos_id_seq'::regclass) | plain | |
account_id | integer | | not null | | plain | |
gst_in | character varying(256) | | not null | | extended | |
gst_reg_address | character varying(256) | | not null | | extended | |
invoice_address | character varying(256) | | not null | | extended | |
state_id | integer | | not null | | plain | |
default | boolean | | not null | false | plain | |
deleted_at | timestamp without time zone | | | | plain | |
Indexes:
"billing_infos_pkey" PRIMARY KEY, btree (id)
"account_id_state_id_deleted_at_uniq_index" UNIQUE, btree (account_id, state_id, deleted_at) WHERE deleted_at IS NULL