Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用on INSERT时出现问题(“从子句条目中缺少”)_Sql_Postgresql - Fatal编程技术网

Sql 使用on INSERT时出现问题(“从子句条目中缺少”)

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

我试图用以前的一些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 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