我试图写一些SQL将记录插入到一个PG表。Postgres的INSERT INTO与SELECT
这是逻辑:
- 对于在costprojects表中的每个记录已coststatus_id = 1
- 插入新的记录到costestimates表
- costcat_id = 30,量= 0, costproject_id = costproject.id(从costprojects记录),维修= 'FALSE',位置= 22
这是SQL代码,我想:
INSERT INTO costestimates (costcat_id, amount, costproject_id, maintenance, position) VALUES (30, 0, costproject.id, false, 22)
(SELECT id FROM costprojects WHERE coststatus_id=1)
我得到错误:语法错误或接近“(”
'INSERT INTO costestimates(costcat_id,金额,costproject_id,维护位置) SELECT 30,0,身份证,假的,22 costprojects WHERE coststatus_id = 1;' –
你不需要()的值,你可以做'插入AA(...)选择1,2,3 ,从X那里xy格式= x.z 4;' – wildplasser
伊尔达·-穆辛 - 感谢 - 如果你回答,我会接受 – Reddirt