tags:

views:

772

answers:

2

Hello, I have the following table:

 tickername | tickerbbname  | tickertype
------------+---------------+------------
 USDZAR     | USDZAR Curncy | C
 EURCZK     | EURCZK Curncy | C
 EURPLN     | EURPLN Curncy | C
 USDBRL     | USDBRL Curncy | C
 USDTRY     | USDTRY Curncy | C
 EURHUF     | EURHUF Curncy | C
 USDRUB     | USDRUB Curncy | C

in which I don't want any of either tickername or tickerbbname column entries ever to be duplicates. I've already created the table and have lots of data in it (which I have already checked to be unique). As it gets larger though, room for error creeps in. Any way of adding UNIQUE constraints ex-post?

Thanks,

A: 

Yes, you can add a UNIQUE constraint after the fact. However, if you have non-unique entries in your table Postgres will complain about it until you correct them.

Jordan S. Jones
+3  A: 

psql's inline help:

\h ALTER TABLE

Also documented in postgres docs (an excellent resource, plus easy to read, too).

ALTER TABLE tablename ADD CONSTRAINT constraintname UNIQUE (columns);

hhaamu
thanks @hhaamu. Yep did try the docs but your above is much more concise.
Thomas Browne