Sql 使用on INSERT时出现问题(“从子句条目中缺少”)
我试图用以前的一些CTE中的信息构建一个新行,但我似乎无法正确理解语法Sql 使用on INSERT时出现问题(“从子句条目中缺少”),sql,postgresql,Sql,Postgresql,我试图用以前的一些CTE中的信息构建一个新行,但我似乎无法正确理解语法 BEGIN; UPDATE users SET balance = balance - 10 WHERE user_id = 1; WITH te AS ( SELECT accountInsertOrSelect('the.hound', 'farcebook', 'rong') AS account_id ), tr AS ( SELECT account_id FROM accounts WHERE us
BEGIN;
UPDATE users
SET balance = balance - 10
WHERE user_id = 1;
WITH te AS (
SELECT accountInsertOrSelect('the.hound', 'farcebook', 'rong') AS account_id
), tr AS (
SELECT account_id FROM accounts
WHERE user_id = 1
AND provider = 'farcebook'
LIMIT 1
)
INSERT INTO tips (tipper_id, tippee_id, amount)
VALUES (te.account_id, tr.account_id, 10);
COMMIT;
给出表“te”的子句条目中缺少的错误
当您尝试插入时,需要在FROM子句中指定CTE,如下所示:
INSERT INTO tips (tipper_id, tippee_id, amount) VALUES
((SELECT account_id FROM te), (SELECT account_id from tr), 10)
或
INSERT INTO tips (tipper_id, tippee_id, amount)
select
(select account_id from te),
(select account_id from tr),
10
INSERT INTO tips (tipper_id, tippee_id, amount)
select te.account_id, tr.account_id, 10
from te cross join tr