13

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", "[email protected]" );

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.

4
  • 15
    Character constants need single quotes. See the manual: postgresql.org/docs/current/static/… Commented Oct 15, 2016 at 10:14
  • @a_horse_with_no_name Thank you. Commented Oct 15, 2016 at 10:16
  • 1
    See also stackoverflow.com/q/1992314/1741542 on single quotes and double quotes. Commented Oct 15, 2016 at 12:32
  • The error message is simply cryptic Commented Jun 11, 2020 at 21:29

2 Answers 2

46

Character constants need single quotes.

Use: INSERT INTO users(user_name, name, password,email) VALUES ('user2','first last','password1', '[email protected]' );

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
2

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", "[email protected]");
            ↑     ↑  ↑          ↑  ↑         ↑  ↑               ↑

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', '[email protected]');
            ↑     ↑  ↑          ↑  ↑         ↑  ↑               ↑

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.