"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> "Francis" <fmarkham@gmail.com> wrote:
>> psql \set does not terminate if a variable is referenced
>> recursively. For example, the following will hang the psql client
>> in a nasty way:
>>
>> db=# \set n 1
>> db=# \set n (:n + 1)
> It seem to me that the above doesn't hang the psql client, but a
> subsequent reference to :n does.
As near as I can tell, it's actually trying to do a recursive expansion
of the variable, which of course doesn't terminate. On my machine it
fails after awhile with
out of dynamic memory in yy_scan_buffer()
xmalloc: out of virtual memory
but you could easily endure a lot of swapping before you get to that,
if your machine isn't carefully configured for amount of swap vs real
RAM vs max allowed process size.
I suppose the only fix is to keep track of which variables are being
actively expanded and refuse to attempt a recursive expansion.
However our options as to what to actually *do* when we detect recursion
are a bit limited. We could print a message and treat the inner
expansion as empty --- is that good enough?
regards, tom lane