小编Sub*_*tra的帖子

PostgreSql 函数中的保存点

我想在 PostgreSQL 的函数中使用保存点功能。我读到保存点不能在 Postgres 的函数内使用。

但是当我回滚时,我想回滚到一个特定的点,因为我想使用保存点。什么是替代方法?

示例代码

CREATE or replace FUNCTION fn_loadData_Subha()
RETURNS BIGINT 
AS 
$$
DECLARE
    batchId BIGINT;   
    currentTime TIMESTAMP;
    processName VARCHAR(20);
BEGIN


-- Getting current date and time
select TIMESTAMP 'NOW' into currentTime;
select 'ETL_Subha' INTO processName;

SAVEPOINT first_savepoint;
-- Inserting new record into batch log table
INSERT INTO TB_HSS_BATCH_LOG
(PROCESS_NAME,START_DATE,STATUS)
SELECT processName,currentTime,'STARTED';

select currval('TB_HSS_BATCH_LOG_id_seq') INTO batchId;

-- Inserting cost data to history table
    Insert into tb_hss_procedure_cost_hist1
    (HOSP_SYSTEM, HOSP_FACILITY, surgeon_name, procedure_name, department, current_dept_rank, no_of_surgeons, current_imp_cost
     , current_med_surg_cost, current_total_cost, …
Run Code Online (Sandbox Code Playgroud)

postgresql plpgsql savepoints

4
推荐指数
1
解决办法
3943
查看次数

标签 统计

plpgsql ×1

postgresql ×1

savepoints ×1