12

I'm using postgresql and I'm trying to insert data into a table users. When I do that using

INSERT INTO users (user_name, name, password,email) 
    VALUES ("user2", "first last", "password1", "user2@gmail.com" );

I get the following error:

ERROR:  column "user2" does not exist

This is how the table looks like:

Table "public.users"
  Column   |       Type    |  Modifiers                        
 user_name | character varying(50)  | 
 name      | character varying(50)  | 
 password  | character varying(50)  | 
 email     | character varying(100) | 
 user_id   | integer                | not null default nextval('users_user_id_seq'::regclass)
Indexes:
    "users_pkey" PRIMARY KEY, btree (user_id)

I was able to insert a row, but it is not working now.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
ashwin mahajan
  • 1,654
  • 5
  • 27
  • 50

2 Answers2

44

Character constants need single quotes.

Use: INSERT INTO users(user_name, name, password,email) VALUES ('user2','first last','password1', 'user2@gmail.com' );

See the manual: postgresql.org/docs/current/static/…

Note: After I encountered the same problem and almost missed the answer that exists in this page (at the comments section), thanks to @a-horse-with-no-name - I've posted this answer

YanivGK
  • 893
  • 12
  • 18
  • 2
    I encountered many bad error messages, but this one is quite interesting. I'm pretty sure I'll end up here again in a year or two. – cglacet May 03 '21 at 12:34
1

You use double quotes for VALUES instead of single quotes. That's why you got the error:

INSERT INTO users (user_name, name, password,email) 
    VALUES ("user2", "first last", "password1", "user2@gmail.com");
            ↑     ↑  ↑          ↑  ↑         ↑  ↑               ↑

So, use single quotes for VALUES instead as shown below, then you can solve the error:

INSERT INTO users (user_name, name, password,email) 
    VALUES ('user2', 'first last', 'password1', 'user2@gmail.com');
            ↑     ↑  ↑          ↑  ↑         ↑  ↑               ↑
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129