Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error message when using INSERT INTO

Here is a Student table I coded in postgreSQL (an excerpt):

CREATE TABLE "Student"
(
  ucas_no integer NOT NULL,
  student_name character(30) NOT NULL,
  current_qualification character(30),
  degree_of_interest character(30),
  date_of_birth date NOT NULL,
  street_address character(30) NOT NULL,
  city character(30) NOT NULL,
  post_code character(10) NOT NULL,
  country character(20) NOT NULL,
  phone_no character(15) NOT NULL,
  gender character(6) NOT NULL,
  user_name character(15) NOT NULL,
  "password" character(30) NOT NULL,
  CONSTRAINT pk_ucas_no PRIMARY KEY (ucas_no),
  CONSTRAINT ten_digits_only CHECK (length(ucas_no::character(1)) >= 10 OR length(ucas_no::character(1)) <= 10)
)

Now i'm using the query tool feature of pgAdmin to insert data into the table. Here's the INSERT INTO code...

INSERT INTO Student
VALUES
('912463857', 'Jon Smith', 'A-Level', 'BSc(Hons) Computer Science', '10/06/1990', '50 Denchworth Road', 'LONDON', 'OBN 244', 'England', '02077334444', 'Male', 'jonsmi', '123456');

The problem I'm having is, i'm getting an error message saying the Student table does not exist, when it's clearly in my databse. Here's the error message:

ERROR:  relation "student" does not exist
LINE 1: INSERT INTO Student (ucas_no, student_name, current_qualific...
                    ^

********** Error **********

ERROR: relation "student" does not exist
SQL state: 42P01
Character: 13

Anyone have an idea what's wrong?

like image 670
Mr Teeth Avatar asked Mar 22 '12 00:03

Mr Teeth


People also ask

What is the correct syntax for insert into?

There are two basic syntax of INSERT INTO statement is as follows: INSERT INTO TABLE_NAME (column1, column2, column3,... columnN)] VALUES (value1, value2, value3,... valueN);

What is the difference between insert and insert into?

If you are using Insert or Insert into both will insert the data in Table. However Insert into is basically used to fatch the data from another table using select command and insert into table where you want to insert the data.

What is the use of insert into?

The INSERT INTO statement is used to insert new records in a table.

Does insert () replace?

You can use the INSERT OR REPLACE statement to write new rows or replace existing rows in the table. The syntax and behavior of the INSERT OR REPLACE statement is similar to the INSERT statement. Unlike the INSERT statement, the INSERT OR REPLACE statement does not generate an error if a row already exists.


1 Answers

you have created a table "Student" and you are trying to insert into a table called Student which are different

try this

INSERT INTO "Student" VALUES('912463857', 'Jon Smith', 'A-Level', 'BSc(Hons) Computer Science', '10/06/1990', '50 Denchworth Road', 'LONDON', 'OBN 244', 'England', '02077334444', 'Male', 'jonsmi', '123456');

This will work

please go through this about qoutes omitting-the-double-quote-to-do-query-on-postgresql

like image 129
PresleyDias Avatar answered Oct 12 '22 23:10

PresleyDias