public inbox for [email protected]  
help / color / mirror / Atom feed
Can we set time exception?
4+ messages / 4 participants
[nested] [flat]

* Can we set time exception?
@ 2023-07-13 14:46  Shaozhong SHI <[email protected]>
  0 siblings, 2 replies; 4+ messages in thread

From: Shaozhong SHI @ 2023-07-13 14:46 UTC (permalink / raw)
  To: pgsql-sql <[email protected]>

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


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* RE: Can we set time exception?
@ 2023-07-13 15:11  Voillequin, Jean-Marc <[email protected]>
  parent: Shaozhong SHI <[email protected]>
  1 sibling, 0 replies; 4+ messages in thread

From: Voillequin, Jean-Marc @ 2023-07-13 15:11 UTC (permalink / raw)
  To: Shaozhong SHI <[email protected]>; pgsql-sql <[email protected]>

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 <[email protected]>
Sent: Thursday, July 13, 2023 4:46 PM
To: pgsql-sql <[email protected]>
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
This email originated from outside of Moody's
Do not click links or open attachments unless you recognize the sender and know the content is safe.
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.


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Can we set time exception?
@ 2023-07-13 15:36  David G. Johnston <[email protected]>
  parent: Shaozhong SHI <[email protected]>
  1 sibling, 1 reply; 4+ messages in thread

From: David G. Johnston @ 2023-07-13 15:36 UTC (permalink / raw)
  To: Shaozhong SHI <[email protected]>; +Cc: pgsql-sql <[email protected]>

On Thu, Jul 13, 2023 at 7:46 AM Shaozhong SHI <[email protected]>
wrote:

> 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.
>
>
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.

If your choice of procedural language can overcome the
synchronous execution limitation then sure.  SQL and pl/pgsql cannot.

David J.


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Can we set time exception?
@ 2023-07-13 15:52  Tom Lane <[email protected]>
  parent: David G. Johnston <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2023-07-13 15:52 UTC (permalink / raw)
  To: David G. Johnston <[email protected]>; +Cc: Shaozhong SHI <[email protected]>; pgsql-sql <[email protected]>

"David G. Johnston" <[email protected]> writes:
> On Thu, Jul 13, 2023 at 7:46 AM Shaozhong SHI <[email protected]>
> 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






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2023-07-13 15:52 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13 14:46 Can we set time exception? Shaozhong SHI <[email protected]>
2023-07-13 15:11 ` Voillequin, Jean-Marc <[email protected]>
2023-07-13 15:36 ` David G. Johnston <[email protected]>
2023-07-13 15:52   ` Tom Lane <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox