将字符串数据类型插入数据库的问题
Issue inserting string datatype into database
我有以下带有子查询的插入查询:
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
当我执行查询时,postgres returns 错误:"ERROR: column "John" 不存在。SQL 状态:42703。字符:110
可能是什么问题?
使用 Single Quotes
而不是 double quotes
。 "
使编译器将其视为标识符。试试这个插入
INSERT INTO Order (time_of_purchase, cust_id)
SELECT NOW(),cust_id FROM Customer WHERE first_name = 'John' AND last_name = 'Doe'
我有以下带有子查询的插入查询:
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
当我执行查询时,postgres returns 错误:"ERROR: column "John" 不存在。SQL 状态:42703。字符:110
可能是什么问题?
使用 Single Quotes
而不是 double quotes
。 "
使编译器将其视为标识符。试试这个插入
INSERT INTO Order (time_of_purchase, cust_id)
SELECT NOW(),cust_id FROM Customer WHERE first_name = 'John' AND last_name = 'Doe'