Re: INSERT UNIQUE row? - Mailing list pgsql-general

From David G. Johnston
Subject Re: INSERT UNIQUE row?
Date
Msg-id CAKFQuwb8U0Yuo3yNokg_yH8ZC725SboVESSE-eAst45AA44EFQ@mail.gmail.com
Whole thread Raw
In response to INSERT UNIQUE row?  (pf@pfortin.com)
Responses Re: INSERT UNIQUE row?  (pf@pfortin.com)
List pgsql-general
On Sun, Jul 9, 2023 at 3:58 PM <pf@pfortin.com> wrote:
Hi,

Trying to figure out how to insert new property addresses into an
existing table.

Can a UNIQUE constraint be applied to an entire row?  Adding UNIQUE to
each column won't work in such a case since there are multiple properties
* on the same street
* in the same town
* with the same number on different streets
* etc...

Each row is only unique as an entity; but the columns are not... 

Is this covered in the docs?


Yes, the mechanics of defining multi-column unique constraints on tables is covered in the docs.

This seems like a waste of space though.  That is a lot of text data (though I suppose not as bad so long as you store integer foreign keys for many of the columns) to put into an index that isn't really even going to catch typos and other malformed data situations while preventing something that is basically impossible to encounter in real life.  Especially if you also have separate individual indexes to make searching for specific subset of the database faster (i.e., everything in a state).

David J.

pgsql-general by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: INSERT UNIQUE row?
Next
From: Adrian Klaver
Date:
Subject: Re: INSERT UNIQUE row?