我正在寻找一个PostgreSQL的等价物下图。我有一个脚本批插入多个表,想法是声明一些变量计数有多少每个已插入时执行。
到目前为止,我已经有了这个,但是对于@@ROW_COUNT还没有直接的方法:
BEGIN TRANSACTION;
DO $$
DECLARE
EmailModulesTotal integer := 0;
DependenciesTotal integer := 0;
ModuleTypesTotal integer := 0;
ModuleSectionsTotal integer := 0;
BEGIN
-- inserts go here
RAISE NOTICE 'Total Inserted/Updated Email Modules: %
Total Inserted Dependencies: %
Total Inserted Module Types: %
Total Inserted Module Sections: %',
EmailModulesTotal,
DependenciesTotal,
ModuleTypesTotal,
ModuleSectionsTotal
END $$;
COMMIT TRANSACTION;
1条答案
按热度按时间h43kikqp1#
在PL/pgSQL中,您可以使用get diagnostics访问受影响(即插入到您的用例中)的行数。
结果为
Inserted 3 rows
普通SQL中的另一种方法是使用数据修改CTE:
哪个更适合你。