2

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?

0

2 Answers 2

5

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);
Sign up to request clarification or add additional context in comments.

3 Comments

This solved the issue lmao, thanks
Not only "in PostgreSQL" this is what the SQL standard requires.
@tanman, if it answers your query, please consider accepting it.
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 ""

1 Comment

saved me so much pain, thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.