12

I am using postgresql and I am 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.

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
ashwin mahajan
  • 1,484
  • 4
  • 23
  • 47

1 Answers1

39

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
  • 711
  • 9
  • 17
  • 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