如何使用子查询作为值之一插入多行?

vin*_*ntf 3 sql postgresql sql-insert

我正在尝试将多行插入到一个表中,其中一列的值来自另一个查询。但是我收到以下错误

用作表达式的子查询返回的多行

我该怎么做?

INSERT INTO 
   accounts_account_preferences (account_id, preference_id) 
VALUES 
   ((SELECT account_id 
     FROM accounts_account_preferences 
     WHERE preference_id = 1), 2);
Run Code Online (Sandbox Code Playgroud)

kli*_*lin 6

INSERT ... SELECT ...不使用VALUES

INSERT INTO accounts_account_preferences (account_id, preference_id) 
SELECT account_id, 2 
FROM accounts_account_preferences 
WHERE preference_id = 1
Run Code Online (Sandbox Code Playgroud)