3
ALTER TABLE users ALTER COLUMN email VARCHAR(50) UNIQUE NOT NULL;
ERROR:  syntax error at or near "VARCHAR"
LINE 1: ALTER TABLE users ALTER COLUMN email VARCHAR(50) UNIQUE NOT ...

I want to alter column email to add its type as UNIQUE NOT NULL in Postgresql and get this error. Can you explain to me what's wrong?

2
  • 1
    I believe it is varying(50) not` varchar(50)`. Commented Mar 4, 2020 at 18:16
  • 1
    @Dan: no, varchar(50) is fine Commented Mar 4, 2020 at 18:38

1 Answer 1

8

You cannot create 2 constraints with one single statement. And you have to use PostgreSQL syntax.

alter table users alter column email set not null;
alter table users add constraint email_unique unique (email);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.