``` create or replace function f1(int) returns setof record as $$ declare begin set local statement_timeout='1ms'; return query select count(*) as cnt, id from a where id<$1 group by id; end; $$ language plpgsql strict ; ```
but it can execute every time, which when the query run more than 1ms.
A quick Google search turns up the response that this is working as designed. In short, the timeout applies to statements sent by the client. Once changed the next statement the client sends to the server will use the new setting. Since a server function invocation is a single statement as far as the client-server relationship goes a timeout set within a function will not apply until the statement the invoked the function ends and a new statement is sent from the client to the server.