0

Hello I am new to postgres and know how to make a column unique however I need to make 2 pairs of columns unique (City,State). I have a table where people insert data different cities and states and I would like to make that pair unique. For Example: Dallas,Texas Houston,Texas Dallas,Texas : This should cause an error or not be allowed because the pair of (Dallas,Texas) is not unique. I am using postgres 9.4 and pgadmin any suggestions would be great

Ignacio Perez
  • 2,341
  • 3
  • 13
  • 18

1 Answers1

5

You can create a unique index on the pair:

create unique index idx_table_city_state on table(city, state);

You can also use a unique constraint in the table definition.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786