【发布时间】:2020-06-19 14:45:05
【问题描述】:
我在这里看到了一些常见 CTE 用例插入多个表的答案,当尝试执行相同的步骤时,我最终得到一个错误提示
缺少表“first_insert”位置 824 的 From 子句条目。
我的CTE表达式如下,
with first_insert as (
insert into listing (title, slug, price, min_quantity, serves, currency_name, currency_symbol, img_url, description,
location, g_map_address, vendor_id)
values ('hello', 'hello-1234', 1, 12, 10, 'eur', '€','url.jpg',
'description', point(24.5498, 16.26), 'gmap', 1)
RETURNING id
),
second_insert as (
insert into category (name, suggested_name, link, rel_link, listing_id)
select 'name', 'name', 'link', 'rel_link', id
from first_insert
),
third_insert as (
insert into allergen (name, suggested_name, link, rel_link, listing_id)
select 'name', 'name', 'link', 'rel_link', id
from first_insert
)
insert into image(listing_id, img_url) select first_insert.id, 'imgUrl';
1 - 我怎样才能让它工作,因为插入不需要从所以甚至不知道从哪里开始
2 - 就性能而言,这是执行这些类型插入的最佳方式吗?
3 - 这是否被归类为安全插入,以便如果任何一个插入失败并且已经执行的插入被回滚?
4 - 就性能和安全性而言,是否有更好的整体插入方式?
【问题讨论】:
标签: node.js postgresql node-postgres