Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.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
长时间运行的PostgreSQL函数返回错误_Sql_Postgresql_Function_Polling_Pgadmin - Fatal编程技术网

长时间运行的PostgreSQL函数返回错误

长时间运行的PostgreSQL函数返回错误,sql,postgresql,function,polling,pgadmin,Sql,Postgresql,Function,Polling,Pgadmin,我有一个非常长的运行函数,需要30多分钟才能完成。它有一个嵌套循环,每次向一个表中插入大约4800万个lead,以10000个为单位。如果我传递了一个小数据集,那么它将成功运行,并给出插入多少引线的正确响应。但是,如果数据集很大,即使它完成了任务,也不会给出任何响应 这里怎么了 这是我的函数代码 CREATE OR REPLACE FUNCTION admin.insert_data_into_table(customer_column_names text[], customer_colum

我有一个非常长的运行函数,需要30多分钟才能完成。它有一个嵌套循环,每次向一个表中插入大约4800万个lead,以10000个为单位。如果我传递了一个小数据集,那么它将成功运行,并给出插入多少引线的正确响应。但是,如果数据集很大,即使它完成了任务,也不会给出任何响应

这里怎么了

这是我的函数代码

CREATE OR REPLACE FUNCTION admin.insert_data_into_table(customer_column_names text[], customer_column_ids int[] , schema_name text, dyn_table_name text, bucket_id int, partial_query text)
 RETURNS integer
 LANGUAGE plpgsql
AS $function$
declare
    n INTEGER := 0;
    offset_counter INTEGER := 0;
    i integer;
    chunk_size integer := 10000;
begin
    EXECUTE format('set search_path to %I', schema_name);
    EXECUTE format('SELECT count(*) FROM %I.%I', schema_name, dyn_table_name) into n;
    for i in 1..array_upper(customer_column_ids, 1)
    loop
        offset_counter = 0;
        loop
        EXIT WHEN offset_counter > n; 
            Execute Format('insert into %s.table (customer_id, customer_column_id, value, bucket_id) 
            select _customer_id, %s, %s, %s from %s.%s %s order by _customer_id offset %s limit %s', 
            schema_name, customer_column_ids[i], customer_column_names[i], bucket_id, schema_name, dyn_table_name, partial_query, offset_counter, chunk_size);
            offset_counter := offset_counter + chunk_size; 
        end loop;
    end loop;
    return n;
end;
$function$;

您是否在每个区块之后提交?@jarlh我没有隐式提交。但是它在函数内部,因为函数是单个事务,所以当函数成功结束时它应该提交。@jarlh块在函数内部管理。分块的意义是什么?为什么不直接插入整个SELECT?如果只运行一个
INSERT。。。选择
语句。