Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INSERT COMMAND :: ERROR: column "value" does not exist

Tags:

sql

postgresql

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", "[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.

like image 794
ashwin mahajan Avatar asked Oct 15 '16 10:10

ashwin mahajan


People also ask

How to use insert COMMAND IN MySQL?

INSERT INTO table_name ( field1, field2,... fieldN ) VALUES ( value1, value2,... valueN ); To insert string data types, it is required to keep all the values into double or single quotes.

How to insert VALUES MySQL?

When inserting a single row into the MySQL table, the syntax is as follows: INSERT INTO table_name(column_1,column_2,column_3) VALUES (value_1,value_2,value_3); In the INSERT INTO query, you should specify the following information: table_name : A MySQL table to which you want to add a new row.

How do you insert if not exists postgresql?

Firstly we have to mention the table name followed by column names (attributes) where we want to insert rows. Secondly, we must enter the values, separated by a comma after the VALUE clause. Finally, every value must be in the same order as the sequence of attribute lists is provided while creating a particular table.

How to insert data IN MySQL 8?

INSERT INTO Syntax It is possible to write the INSERT INTO statement in two ways: 1. Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)


Video Answer


1 Answers

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

like image 199
YanivGK Avatar answered Sep 20 '22 01:09

YanivGK