2

I thought immutable strict ment the database could not be modified.

The following inserts a new row in 'some_table':

CREATE FUNCTION insert_row() RETURNS void AS
$$
  plv8.execute('INSERT INTO some_table (number) VALUES ($1)', [123]);
$$
LANGUAGE plv8 IMMUTABLE STRICT;

Is it not possible to prevent a function modifying the database?

Jacob
  • 1,642
  • 2
  • 15
  • 27
  • 4
    The [volatility category](http://www.postgresql.org/docs/current/interactive/xfunc-volatility.html) of a function is mostly a promise your function makes to PostrgreSQL, your function can lie but you shouldn't expect anything good to come of it. – mu is too short Jun 28 '14 at 22:36

1 Answers1

0

This works as expected for me.

If I execute something like:

select insert_row() from some_OTHER_table;

I get EXACTLY one new row in some_table regardless of the number of rows in some_other_table.

If you don't want your function modifies your database, simply DON'T put insert or update statements in it.

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
bitifet
  • 3,514
  • 15
  • 37
  • I only tryed to help. (Sorry for that). As you noticed, I can't comment (I don't understand why if I can answer...) but you're right. Maybe this could be better inserted as a comment (as I can't do). Sorry again for trying to help. – bitifet Nov 19 '14 at 20:07