Skip to content
Advertisement

Can’t give PRIMARY KEY property in POSTGRES

Why doesn’t this work exactly?

ALTER TABLE IF EXISTS public.post 
    ALTER COLUMN id TYPE INTEGER PRIMARY KEY
    OWNER to postgres;

The error is

syntax error at or near “PRIMARY”

Advertisement

Answer

The syntax for PostgreSQL is as follows :

Try with this:

ALTER TABLE IF EXISTS public.post 
ADD PRIMARY KEY (id);

Documentation : https://www.postgresqltutorial.com/postgresql-primary-key/

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