Reputation: 119
I have the following insert query with a subquery:
INSERT INTO Order (time_of_purchase, cust_id)
VALUES (NOW(), (SELECT cust_id FROM Customer WHERE first_name = "John" AND last_name = "Doe")) RETURNING reference_number
When I execute the query, postgres returns the error: "ERROR: column "John" does not exist. SQL state: 42703. Character: 110
What could be the problem?
Upvotes: 1
Views: 137
Reputation: 93704
Use Single Quotes
instead of double quotes
. "
makes the compiler to consider it as identifier. Try this insert
INSERT INTO Order (time_of_purchase, cust_id)
SELECT NOW(),cust_id FROM Customer WHERE first_name = 'John' AND last_name = 'Doe'
Upvotes: 3