From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: why VOLATILE attribute is required? |
Date: | 2011-09-22 12:50:06 |
Message-ID: | CAHyXU0yuZ7DQe8+-__Vk9bKWB31p3NfZfRJQgq3aG0xHDH_=PQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Sep 22, 2011 at 5:28 AM, Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com> wrote:
> Hi All,
>
> I have this function:
> CREATE FUNCTION mypass(newpass text) returns text ....
> EXECUTE 'ALTER USER ' || quote_ident(session_user) || ' PASSWORD ' ||
> quote_literal(newpass); return session_user::text;
>
> to varify user passwords before allowing a change.
>
> I've put that function in a RULE that some housekeeping, like updating
> user state (last pass change, etc):
>
> CREATE RULE pass AS ON UPDATE TO myself WHERE old.pass <> new.pass DO
> INSTEAD UPDATE people SET .... WHERE username=mypass(new.username)
>
> but I get:
> ERROR: ALTER ROLE is not allowed in a non-volatile function
>
> Why???
>
> 1. The function is "obviously STABLE", since it's outcome will not
> change enything in datatables (I think) - and I can arrange for its
> output being stable within a transaction (if I don't do SET
> AUTHORIZATION within the transation, right?).
> 2. for the purpose I need, the function could/should be "computted
> once", and result used "meny times" (for filtering PEOPLE rows). Having
> it get evaluated for every row is a signifficant unnecesary cost
> panelty.
if you change the state of the database, including (and especially)
system catalogs, your function is volatile, period.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Albe Laurenz | 2011-09-22 12:53:28 | Re: Problem dbi_link with postgresql 9.04 |
Previous Message | Alban Hertroys | 2011-09-22 12:32:06 | Re: looking for a faster way to do that |