Re: 9.5 Create Function Set From Current taken at creation time?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: 9.5 Create Function Set From Current taken at creation time?
Date: 2016-08-09 13:27:42
Message-ID: CAKFQuwbtGWGPO4EhNwwtOQBAiw3raQzVKqF83=siOq3iev5tUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Aug 9, 2016 at 9:10 AM, Peter Eisentraut <
peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:

> On 8/8/16 5:46 PM, David G. Johnston wrote:
> > """
> > The SET clause causes the specified configuration parameter to be set to
> > the specified value when the function is entered, and then restored to
> > its prior value when the function exits. SET FROM CURRENT saves the
> > session's current value of the parameter as the value to be applied when
> > the function is entered.
> > """
> >
> > https://www.postgresql.org/docs/current/static/sql-createfunction.html
> >
> > I expect the attached script to output "NOTICE: SP : thirdschema",
> > instead it outputs "NOTICE: SP: otherschema"
>
> I think the piece you are missing is that it saves the setting when the
> function is created, not when it is run.
>

With hindsight ​I understand this perfectly (and I swear I've brought this
up before and subsequently forgot)...

​Can we change the second sentence in the above quote to something like:​

​SET FROM CURRENT is a convenience expression to capture the result of
current_setting('setting name') at the time of the function's creation. [if
more than just convenience an example of when this is useful would be nice].

The fact that there is no way obtain the useful "restored to its prior
value" behavior without specifying an explicit value is a short-coming, not
a bug. That said, changing search_paths in a function is likely asking for
trouble anyway so the lack probably isn't something worth fixing.

​David J.​


In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrew Gierth 2016-08-09 13:30:58 Re: BUG #14228: replication slot catalog_xmin not cleared on slot reuse
Previous Message Peter Eisentraut 2016-08-09 13:10:04 Re: 9.5 Create Function Set From Current taken at creation time?