开发者

bulk/multiple queries that take a long time never finish in Postgres

I have created a function in postgres that inserts data into a table. The function receives a string and enters the value into a table after processing it. What I want is to be able to call the function numerous times in pgAdmin instead of running them in batches.

Example: in pgAdmin i open up my sql query window and type

select customfunction('string1');
select customfunction('string2');
           ^
           .
           .
           .
           .
       开发者_StackOverflow    v
select customfunction('string100000000');

When I try to run this it only works when I run about 6000 lines (6000 functions). If i cancel it while it is running it doesnt commit anything (not even the first line). I have to keep cutting them into batches to complete the entire query. How can I achieve this without running them in batches.

I want to copy and paste the whole query and wait till everything is done. Right now the query just runs with no response indefinitely if i run over 10000 lines in a batch. Is there a way postgres can commit each line once it runs that line?

I would also like to know if anyone can determine exactly what line is being processed while the query is running.


Is there a way postgres can commit each line once it runs that line?

It won't do that if auto-commit is enabled - that is the default, too, so... Are you preceding the calls with a begin statement? If so commit before making your calls...

Also, consider preparing the statement or doing what jack suggested.


Have you tried batching your strings to file, importing the file into a table (which I'll call string_table with a single column called string), and trying:

select customfunction(string)
from string_table;

ETA: If you want some kind of progress indicator and need to run one select at a time, you could use a DBI in a scripting language to read the strings from either a file or a table, iterate through the function calls in a loop, and then do a simple console printout with each iteration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜