0

I was trying to create a generated column. It should be output of some function with parameter as one of its column, e.g. custom_function(column1). where custom_function is a user defined function of postgresql and column1 is any column of the table. Actual query is as below-

ALTER TABLE ttt.test
    ADD COLUMN "checkDigit" char GENERATED ALWAYS AS (ttt.getfunction(actual_sn)) STORED;

But getting error 'ERROR: generation expression is not immutable'

wildplasser
  • 43,142
  • 8
  • 66
  • 109
  • 2
    The error message is pretty clear: your generation expression (`ttt.getfunction(actual_sn)`) is not [immutable](https://www.postgresql.org/docs/current/xfunc-volatility.html). If your function is immutable, mark it as such. If it's not, you may need to consider a different solution. – Nick Barnes Oct 08 '21 at 10:27
  • @NickBarnes: Thanks for your quick reply. It worked after making the function IMMUTABLE. – siddhartha attri Oct 08 '21 at 11:09

1 Answers1

0

It worked after making the function(ttt.getfunction) IMMUTABLE.