In a function we r finding max value of a column which is hving an id value and then incrementing the column value by adding 1 to the value . now we have to check if max value is zero (ie that column has no value) then we have to write 1 in the column and start incrementing them. how to do this. plz reply as soon as possible.
maximum function
Collapse
X
-
If your function is written in plpgsql you should learn here about control structures
If you preferred to use SQL then read about conditional expressions
You may also be interested in using a sequence
This way you'll never have to worry about checking for NULL or incrementing value.
What is also important sequence will provide safety, otherwise you may need to lock the table to prevent two processes intervening with each other in the process of checking/incrementing the value.
Comment