Search code examples
postgresqlgenerated-columns

Postgresql: Generated column as output from a function


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'


Solution

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