2

Say you want to create a new table in a database. If you run a script that only contains the CREATE... code, then it will work the first time, but crash if run again, since it will be trying to create an object that already exists. By adding IF EXISTS ... logic (or DROP TABLE ...) first however, you can avoid such errors.

I know there is a specific technical term that describes this concept or property, i.e. the ability of a script to be run multiple times without changing the end result from the result of running the script only once, but I can not seem to recall it, and I have not been able to find it. Multi-something-something? or poly-something-something?

Kjartan
  • 18,591
  • 15
  • 71
  • 96
  • 1
    Do you mean DETERMINISTIC? – jarlh Oct 02 '19 at 10:06
  • Thanks, but no - there I know for a fact that there is some special term that has the specific meaning described above. – Kjartan Oct 02 '19 at 10:36
  • @Kjartan . . . I think jarlh is correct. "DETERMINISTIC" captures that notion at least for SQL stored procedures. I use the term "stable" for queries that have `ORDER BY` with unique keys, but that is specific to sorting. – Gordon Linoff Oct 02 '19 at 11:09

1 Answers1

3

Idempotent operations

can be applied multiple times without changing the result beyond the initial application.

For example, function f is idempotent if for all inputs x it holds

f(x) == f(f(x))

I have often encountered the concept within the context of idempotent HTTP requests, and within the context of functional programming as referential transparency.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98