Skip to content
Advertisement

SQL unique index explaination

I have seen this for the first time. This is a section in liquibase for defining the unique columns in a table. But I don’t understand which columns are unique.

<sql dbms="postgresql">
        CREATE UNIQUE INDEX
        invoice_tax_id_null_index ON
        invoice_table
        (invoice_profit_id, invoice_account_id, tax_id,
        country_id,
        COALESCE(invoice_tax_id, -1))
    </sql>

Are all of the columns mentioned here unique? For example

invoice_tax_id
invoice_profit_id
invoice_account_id
tax_id
country_id

Or is only

invoice_tax_id

unique?

How to read that? Thank you very much.

Advertisement

Answer

The unique index specifies 5 columns, so generally this means that no two records in the invoice_table can have the same 5 values at the same time. Attempting to do an insert with 5 values already existing in some other record would generate an error.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement