How can I set a timeout for a locked table in Function ?

2020-01-03 Thread İlyas Derse
CREATE OR REPLACE FUNCTION public."testlock"() RETURNS TABLE ( id integer, name character varying, state integer, owner character varying ) LANGUAGE 'plpgsql' AS $BODY$ BEGIN

RE: How can I set a timeout for a locked table in Function ?

2020-01-03 Thread Patrick FICHE
Hi, You cannot set the statement_timeout within a function. You have to set it before you call the function. For example, you can try : BEGIN; SET LOCAL statement_timeout = 6000; SELECT * from public.”testlock”(); COMMIT; The reason why is explained in this post : https://dba.stackexchange.c

Re: How can I set a timeout for a locked table in Function ?

2020-01-03 Thread Michael Lewis
I would not think that behavior would extend to lock_timeout based on the explanation on stackexchange. I would assume that the potentially long runtime in this function is mostly in acquiring the lock and not doing the update given the implied primary key in the where clause, so perhaps lock_timeo

Re: How can I set a timeout for a locked table in Function ?

2020-01-03 Thread Thomas Kellerer
Michael Lewis schrieb am 03.01.2020 um 18:00: Why take an exclusive lock on an entire table to update a single row? That's what I was asking myself as well.

Are PostgreSQL functions that return sets or tables evaluated lazily or eagerly?

2020-01-03 Thread Gerald Britton
Cross post from Stack Overflow: https://stackoverflow.com/questions/59554144/are-postgresql-functions-that-return-sets-or-tables-evaluated-lazily-or-eagerly I'm learning to write functions in PostgreSQL. When I got to the documentation chapter on cursors, I came across this interesting comment:

Re: Are PostgreSQL functions that return sets or tables evaluated lazily or eagerly?

2020-01-03 Thread Tom Lane
Gerald Britton writes: > I'm learning to write functions in PostgreSQL. When I got to the > documentation chapter on cursors, I came across this interesting comment: > A more interesting usage is to return a reference to a cursor that a > function has created, allowing the caller to read the rows.

Re: Are PostgreSQL functions that return sets or tables evaluated lazily or eagerly?

2020-01-03 Thread Andrew Gierth
> "Gerald" == Gerald Britton writes: Gerald> That leads me to ask: Gerald> If (and under what circumstances) PostgreSQL evaluates Gerald> functions lazily (returning rows as requested by the caller) or Gerald> eagerly (evaluation all rows before returning the first one)? This isn't triv