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.
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.
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.
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.
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, ...)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With