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.

  • Just don't use reserved words. It will cause more problems than it solves. – ferhat elmas Jan 12 '16 at 17:31
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
);
  • And don't forget to use quotes in every query you execute on this table, "user" will always be a reserved word. – Frank Heikens Feb 28 '11 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, privacy policy and cookie policy

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