Does IMMUTABLE have any effect on functions?

From: Thomas Schoen <t(dot)schoen(at)vitrado(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Does IMMUTABLE have any effect on functions?
Date: 2005-03-03 13:17:17
Message-ID: 42270E5D.3020607@vitrado.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2005-03-03 13:56:55 Re: Does IMMUTABLE have any effect on functions?
Previous Message Stephane Bortzmeyer 2005-03-03 13:06:28 Re: [Auth] "ident" method and LDAP user accounts