Does IMMUTABLE have any effect on functions? - Mailing list pgsql-general

From Thomas Schoen
Subject Does IMMUTABLE have any effect on functions?
Date
Msg-id 42270E5D.3020607@vitrado.de
Whole thread Raw
Responses Re: Does IMMUTABLE have any effect on functions?
Re: Does IMMUTABLE have any effect on functions?
List pgsql-general
Hi,

i wonder if the attribute IMMUTABLE has any effect on functions.
Maybe its not implemented yet?

I tried the following:

CREATE TABLE foo (bar int4);

CREATE FUNCTION foo(int4)
RETURNS int4
AS '
     INSERT INTO foo (bar) VALUES ($1);
     SELECT $1;
' LANGUAGE 'sql' IMMUTABLE;

...now without any transaction...

select * from foo(1);

  foo
-----
    1
(1 row)

SELECT * FROM foo;

  bar
-----
    1
(1 row)

select * from foo(1);

  foo
-----
    1
(1 row)

SELECT * FROM foo;

  bar
-----
    1
    1
(1 row)


In my expectations the 2nd function call should not have added a new row
to table "foo", beacause it was called with the same parameter and is
immutable.

The same happens when i try to call the function twice within a single
transaction.

Maybe the "IMMUTABLE" attribute is just some sort of comment?

greets, Tom Schön

pgsql-general by date:

Previous
From: Stephane Bortzmeyer
Date:
Subject: Re: [Auth] "ident" method and LDAP user accounts
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Does IMMUTABLE have any effect on functions?