1

I'm new in PostgreSQL. I try to create table in database. In psql i write:

CREATE TABLE mail_user (
   user char(50) NOT NULL,
   domain char(50) NOT NULL,
   password char(50) NOT NULL
);

But i get error:

ERROR: syntax error at or near "user" LINE 2: user char(50) NOT NULL, ^

What's wrong? How can i fix it?

Thank you.

1
  • Just don't use reserved words. It will cause more problems than it solves. Jan 12, 2016 at 17:31

2 Answers 2

5

You can use reserved words by quoting them:

CREATE TABLE mail_user (
   "user" char(50) NOT NULL,
   domain char(50) NOT NULL,
   password char(50) NOT NULL
);
1
  • And don't forget to use quotes in every query you execute on this table, "user" will always be a reserved word. Feb 28, 2011 at 8:58
7

"user" is a reserved word. You may want to try "username" instead. http://www.postgresql.org/docs/8.3/static/sql-keywords-appendix.html

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.