Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

sql - Run query again once finished n times

I'm working in a psql database and I want to leave something running overnight.

I have a function I am calling like this:

select func_name(21);

This function is transactionalised and once ran, inserts to the DB.

I then want to run the same function again (it has highwater marks, so it will know where to pick up from):

select func_name(21);

Lets say I want to run this 10 times - is this possible?

I had considered using something like gexec but unsure how to make it work.

I can get the following:

select format('select func_name(%s)',id) from table where id = '21';
                   format                   
--------------------------------------------
 select func_name(21)
(1 row)

I know if I execute this using gexec it will run once but is there a way I can get it to run ten times without using a loop within another function?

question from:https://stackoverflow.com/questions/65835438/run-query-again-once-finished-n-times

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is exactly what I was looking for:

                   format                   
--------------------------------------------
 select func_name(21)
 select func_name(21)
 select func_name(21)
 select func_name(21)
 select func_name(21)
 select func_name(21)
 select func_name(21)
 select func_name(21)
 select func_name(21)
 select func_name(21)

From here, I could run a gexec command


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...