Converting mySQL KEY to PgSQL?

I am converting some mySQL code to pgSQL and I am facing this problem

mysql code: "KEY ug_main_grp_id (ug_main_grp_id)"

Which would be the equivalent in PgSQL. At first I thought I could just use CREATE INDEX in pgSQL, but that really doesn't fit because KEY is not an index: P

+1


a source to share


5 answers


KEY

is the index if that's the exact syntax you are wrapping.



+2


a source


Given your example: KEY ug_main_grp_id (ug_main_grp_id)

you can add right after the instruction CREATE TABLE

:



CREATE INDEX ug_main_grp_id ON TheTableName ( ug_main_grp_id );

      

+2


a source


PRIMARY KEY (ug_main_grp_id)

      

0


a source


If they are unique, just use UNIQUE, as in:

mycolumn int NOT NULL UNIQUE

      

but if it is not unique, you need to use the CREATE INDEX command.

0


a source


You don't need to do anything special in pgsql, if you have multiple indexes, it will determine which ones will be used for a given query automatically.

0


a source







All Articles