Thread: Can we set time exception?
create or replace function shi() returns text as $$
declare
ts timestamp:=clock_timestamp();
begin
perform pg_sleep(2);
if extract ('epoch' from age(clock_timestamp(),ts))>2 then
return 'timeout';
else
return 'ok';
end if;
end;$$ language plpgsql;
From: Shaozhong SHI <shishaozhong@gmail.com>
Sent: Thursday, July 13, 2023 4:46 PM
To: pgsql-sql <pgsql-sql@lists.postgresql.org>
Subject: Can we set time exception?
In a Do statement, it calls function to work? Can we set a time exception? If the function responds with result in a given time, we take the result. If the response of the function exceeds the time set, skip it. Regards, David
ZjQcmQRYFpfptBannerStart
|
ZjQcmQRYFpfptBannerEnd
In a Do statement, it calls function to work?
Can we set a time exception?
If the function responds with result in a given time, we take the result.
If the response of the function exceeds the time set, skip it.
Regards,
David
Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.
In a Do statement, it calls function to work?Can we set a time exception?If the function responds with result in a given time, we take the result.If the response of the function exceeds the time set, skip it.
"David G. Johnston" <david.g.johnston@gmail.com> writes: > On Thu, Jul 13, 2023 at 7:46 AM Shaozhong SHI <shishaozhong@gmail.com> > wrote: >> Can we set a time exception? >> If the function responds with result in a given time, we take the result. >> If the response of the function exceeds the time set, skip it. > No. Function execution happens on a single thread (i.e., synchronous) in a > stacked manner. There is no way for the caller to get processing control > back other than the callee returning. You could do something with statement_timeout, but the recovery would have to be managed on the client (application) side. IIRC we measure that as the total time to finish a client query, not the time of any one statement within a function or DO block. regards, tom lane