Skip to content
Advertisement

Can I add a UNIQUE constraint to a PostgreSQL table, after it’s already created?

I have the following table:

I don’t want there to ever be more than one column for any given tickername/tickerbbname pair. I’ve already created the table and have lots of data in it (which I have already ensured meets the unique criteria). As it gets larger, though, room for error creeps in.

Is there any way to add a UNIQUE constraint at this point?

Advertisement

Answer

psql‘s inline help:

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

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