Re: INSERT UNIQUE row?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pf(at)pfortin(dot)com
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: INSERT UNIQUE row?
Date: 2023-07-09 23:42:15
Message-ID: CAKFQuwb8U0Yuo3yNokg_yH8ZC725SboVESSE-eAst45AA44EFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Jul 9, 2023 at 3:58 PM <pf(at)pfortin(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2023-07-10 00:04:03 Re: INSERT UNIQUE row?
Previous Message Christophe Pettus 2023-07-09 23:02:14 Re: INSERT UNIQUE row?