I would like to find a way to store multiple addresses for one subject in my database, with only one default address per subject.
To cut a long story short, lets say we have a table:
CREATE TABLE test
(
id integer NOT NULL,
active boolean NOT NULL,
CONSTRAINT pk_id PRIMARY KEY (id)
)
For each id in the table, there must be at most 1 true active value.
How could I achieve this?
Thanks.
id
being the primary key makes it unique so there cannot be two rows with the same ID. – ThiefMaster♦ Jun 13 '12 at 12:37id
as primary then you will need to write a trigger: postgresql.org/docs/9.1/static/sql-createtrigger.html but thats probably not what you want. – Adam Gent Jun 13 '12 at 12:51