Coder Perfect

I’m having trouble getting a simple PostgreSQL insert to function.

Problem

I’m attempting to perform a simple insert into a Postgres table, but I’m receiving an error stating that the value I’m attempting to put is being interpreted as a column name.

INSERT INTO "imageTagBusinessMainCategory"
(id, businessMainCategory)
VALUES
(DEFAULT, "auto dealer")

Where the main key is configured to be id, with auto increment and not null. When I set up the table in phpPgAdmin, I checked those boxes.

However, I’m getting the following error:

ERROR: ERROR: column "auto dealer" does not exist
Query = INSERT
INTO "imageTagBusinessMainCategory"
(id, businessMainCategory)
VALUES
(DEFAULT,
"auto dealer")

As suggested here, I’ve put my table name in double quotes.

As I’ve read here, I should use DEFAULT to auto-increment the id.

Any ideas? Thanks!

Asked by 1252748

Solution #1

r identifiers, and’for strings as quotations

Also:

Answered by Matt

Solution #2

INSERT INTO "imageTagBusinessMainCategory"
("businessMainCategory")
VALUES
('auto dealer')

EDIT: Double-quotes around the column name have been added.

Answered by Randy

Solution #3

If the column name has mixed case, Postgres, Oracle, and other databases expect it to be in quotes. So, either use all tiny or all caps for your table columns, or, as David Faber advised, use quotations.

INSERT INTO "imageTagBusinessMainCategory"
("businessMainCategory")
VALUES
('auto dealer')

Answered by randomness

Solution #4

In my case, I had to alter the name of the column from camel to something else. Snake case ‘is admin’ to case ‘isAdmin’.

Answered by Cristea

Post is based on https://stackoverflow.com/questions/12428496/cannot-get-simple-postgresql-insert-to-work