Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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 当其中一个值参数是动态的时,是否可以执行多个插入?_Sql_Postgresql - Fatal编程技术网

Sql 当其中一个值参数是动态的时,是否可以执行多个插入?

Sql 当其中一个值参数是动态的时,是否可以执行多个插入?,sql,postgresql,Sql,Postgresql,考虑以下Postgresql数据库表: id | book_id | author_id ---------------------------- 1 | 17 | 10 2 | 18 | 10 3 | 19 | 10 4 | 22 | 10 我想在此表中插入新的author\u id值,其中author\u id=10。例如,生成的表类似于以下内容 id | book_id | author_id ---

考虑以下Postgresql数据库表:

id    | book_id |  author_id
----------------------------
 1    |  17     | 10
 2    |  18     | 10
 3    |  19     | 10
 4    |  22     | 10
我想在此表中插入新的author\u id值,其中author\u id=10。例如,生成的表类似于以下内容

id    | book_id |  author_id
----------------------------
 1    |  17     | 10
 2    |  18     | 10
 3    |  19     | 10
 4    |  22     | 10
 5    |  17     | 11
 6    |  18     | 11
 7    |  19     | 11
 8    |  22     | 11     
如果不为每个图书id编写单独的insert语句,是否可以编写一个模拟相同行为的insert语句?

试试这个

Insert into table(book_id,author_id)
(
    Select table.book_id,11 FROM table
    Where author_id=10
)