views:

80

answers:

3

I'm converting some mySQL code to pgSQL and I've run into this problem

mysql code : "KEY ug_main_grp_id (ug_main_grp_id)"

What would be the equivalent in PgSQL. First I thought I could just use CREATE INDEX in pgSQL, but that's really not appropriate because KEY is not an index :P

+1  A: 

KEY is an index, if that's the exact syntax you're porting.

Rob
A: 
PRIMARY KEY (ug_main_grp_id)
Curt Sampson
And yes, it is implemented as an index, as most DBMSes do, but that is, as the statement indicates, an implementation detail....
Curt Sampson
Thanks. I added a comment above, what if I have multiple Keys and I already have a PKey
A: 

If they key is unique, just use UNIQUE as in:

mycolumn int NOT NULL UNIQUE

but if it's a non-unique one, you need to use the CREATE INDEX command.

Magnus Hagander