1

I'm trying to populate the tables in database but am getting an error that the column does not exist. Can someone direct me where I am going wrong. Below is my query:

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES  (Shire, Robert,  206-524-2422, 12/14/2017, AntiqueDesk,3000.00, 249.00, 329.00);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES  (Shire, Robert, 206-524-2422, 12/14/2017, ‘AntiqueDeskChair’, 500.00, 41.50, 541.50);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Goodyear,Katherine,206-524-3544, 12/15/2017, ‘DiningTableLinens’, 1000.00, 83.00, 1083.00);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Bancroft, Chris, 426-635-9788, 12/15/2017, Candles, 50.00, 4.16, 54.16);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Griffith, John, 206-524-4656, 12/23/2017, Candles, 45.00, 3.74, 48.74);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Shire, Robert, 206-524-2422, 1/5/2018, DeskLamp, 250.00, 20.75, 270.75);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Tierney, Doris, 425-635-8677, 1/10/2018, DiningTableLinens, 750.00, 62.25, 812.25);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Anderson, Donna, 360-538-3544, 1/12/2018, BookShelf, 250.00, 20.75, 270.75);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Goodyear, Katherine, 206-524-544, 1/15/2018, AntiqueChair, 1250.00, 103.75, 1353.75);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Goodyear, Katherine, 206-524-544, 1/15/2018, AntiqueChair, 1750.00, 145.25, 1895.25);

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES (Tierney, Doris, 425-635-8677, AntiqueCandleHolders , 350.00, 29.05, 379.05)
4
  • 4
    You need to surround the strings with single qotes; otherwise the database thinks that they are column names. Voting to close this as a typo. Commented Jan 26, 2020 at 21:00
  • 2
    Dates also require proper formating and quoting. Commented Jan 26, 2020 at 21:02
  • what is the table definition and what is the actual error? Commented Jan 26, 2020 at 21:05
  • I added the quotes and still got the error: ERROR: column "‘shire’" does not exist LINE 2: VALUES (‘Shire’, ‘Robert’, 206-524-2422, 12/14/2017, ‘Ant... ^ SQL state: 42703 Character: 95 Commented Jan 26, 2020 at 21:10

2 Answers 2

1

All the values you are inserting need to be between single quotes for example:

INSERT INTO Sales (LastName,FirstName,Phone,InvoiceDate,InvoiceItem,Price,Tax,Total)
VALUES  ('Shire', 'Robert',  '206-524-2422', '12/14/2017', 'AntiqueDesk', '3000.00', '249.00', '329.00');

It will work: https://dbfiddle.uk/?rdbms=postgres_9.4&fiddle=bdc47dea28c109aafb26aac1e8e5d856

Sign up to request clarification or add additional context in comments.

3 Comments

This is not necessarily true. It would be reasonable to suppose the the last three values are some sort of numeric type, in which case they do not need quotes. Also your date format is dependent on locale. It is better to use a format that is universal.
@JonathanWillcock I do not agree that it would be reasonable to suppose anything... With the data from the question this is ok answer. It is an answer to the error OP has... Also, what will happen to the numeric values in the single quotes ?
@VBoka I was hinting that your answer would be better if you at least suggested that the last three should be numerics. It may well be that they are not in fact numeric in the database (we have no way of telling) but they should be. Assuming they are, then IMHO it is bad practice to quote them: firstly it forces the database to do an unnecessary parse; and secondly it is also locale specific (Western European locales, for example, have '.' as the thousand separator). So whilst quoting them may well work, it should still be avoided, if possible.
0

I got the same error when using double quotes for VALUES instead of single quotes as shown below:

                                               ↓    ↓  ↓     ↓
postgres=# INSERT INTO store_person VALUES (1, "John", "Smith");
ERROR:  column "John" does not exist

So, I used single quotes for VALUES instead, then the error was solved and I could insert a new row:

                                               ↓    ↓  ↓     ↓
postgres=# INSERT INTO store_person VALUES (1, 'John', 'Smith'); 
INSERT 0 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.