How to Solve Error Message Cannot Create user Table in PostgreSQL Database Server

Posted on

Introduction

This is another article where the focus is going to solve a certain error message. The error message exist as part of the article’s title. It informs that the process for creating a table with the name of ‘user’ ends in failure. The full and complete error message exist as in the following execution sequence :

  1. The first step is accessing the command line interface. That command line interface is a Command Prompt as follows :

    Microsoft Windows [Version 10.0.18363.628]
    (c) 2019 Microsoft Corporation. All rights reserved.
    C:\Users\Personal>psql -Upostgres -p
    psql: option requires an argument -- p
    Try "psql --help" for more information.
    C:\Users\Personal>
    
  2. After successfully executing the Command Prompt, the following after is executing the command for accessing the PostgreSQL command console as follows :

    C:\Users\Personal>psql -Upostgres
    Password for user postgres:
    psql (14.2)
    WARNING: Console code page (437) differs from Windows code page (1252)
    8-bit characters might not work correctly. See psql reference
    page "Notes for Windows users" for details.
    Type "help" for help.
    postgres=#
    
  3. Continue on the previous step, connect to the database for further process to create a table. The pattern for connecting to the database is ‘\c db_name’. In this context, the ‘db_name’ is ‘db_apps’ as follows :

    postgres=# \c db_apps
    You are now connected to database "db_apps" as user "postgres".
    db_apps=#
    
  4. Executing the query for creating the table with the name of ‘user’ below :

    db_apps=# create table user(user_id int auto_increment, email_id varchar(55), password varchar(55), first_name varchar(55), last_name varchar(55), primary key(user_id));
    ERROR: syntax error at or near "user"
    LINE 1: create table user(user_id int auto_increment, email_id varch..
    db_apps=#
    

Create Table User in PostgreSQL Database Server

So, how is the actual solution for solving the problem triggering the error message ?. Actually, the solution is very simple for solving it. Just change the name of the table. It seems that the ‘user’ keyword for the name of the table is forbidden and it is part of the reserved keyword. So, instead of using ‘user’ string for the keyword name of the table, just change it into another string. For an example, change it from ‘user’ to ‘users’ as follows :

db_apps=# create table users(user_id int primary key, email_id varchar(55), password varchar(55), first_name varchar(55), last_name varchar(55));
CREATE TABLE
db_apps=#

One thought on “How to Solve Error Message Cannot Create user Table in PostgreSQL Database Server

Leave a Reply