1

PostgreSQL 13, pgAdmin 4.

I have a table "Student" with the following columns:

  • student_id (text, primary key)
  • last_name (text)
  • first_name (text)
  • major (text)
  • credit_hours (int)

I'm simply trying to add another student to this table, which I am attempting to do with the query below

INSERT INTO Public."Student" ("student_id", "last_name", "first_name", "major", "credit_hours")
VALUES ("S201217","BAR","FOO","CSC",100);

but when I run this query, I get this output

ERROR:  column "S201217" does not exist
LINE 2: VALUES ("S201217","BAR","FOO","CSC",100);
                ^
SQL state: 42703
Character: 105

For such a basic error, I really must be missing something here, why is this query not able to add a row?

tanman
  • 19
  • 1
  • 4

2 Answers2

3

Double quotes are used to quote columns. Use single quotation instead of double.

INSERT INTO Public."Student" ("student_id", "last_name", "first_name", "major", "credit_hours")
VALUES ('S201217','BAR','FOO','CSC',100);
devReddit
  • 2,696
  • 1
  • 5
  • 20
1

DB engine thinks this "S201217" is the column name, do single quotes and you'll be fine

INSERT INTO Public."Student" (student_id, last_name, first_name, major, credit_hours)
VALUES ('S201217','BAR','FOO','CSC',100);

You need "" if you using it for naming such has capitals of a break-in the string, for example, your table, as it starts with capital S it should be in double quotes, for column names no need it. or for example, if doing select

Select now() as 'Time now'

because alias has empty string and capital letter you need to include in ""

Andrey
  • 1,629
  • 13
  • 37
  • 65