views:

1235

answers:

2

I have a table in PostgreSQL where the schema looks like this:

CREATE TABLE "foo_table" (
    "id" serial NOT NULL PRIMARY KEY,
    "permalink" varchar(200) NOT NULL,
    "text" varchar(512) NOT NULL,
    "timestamp" timestamp with time zone NOT NULL
)

Now I want to make the permalink unique across the table by ALTER-ing the table. Can anybody help me with this?

TIA

A: 

I don't know much about PostgreSQL, but in most DBMS'es you create a column 'unique' by applying a unique constraint or unique index on that column. I believe that this will not be any different in Postgres.

So, it should be something like

ALTER TABLE foo ADD UNIQUE CONSTRAINT (thecolumn)
Frederik Gheysels
+6  A: 

I figured it out from the PostgreSQL docs, the exact syntax is:

ALTER TABLE the_table ADD CONSTRAINT constraint_name UNIQUE (thecolumn);

Thanks Fred.

Baishampayan Ghose