Skip to content

Policy that limits colums that can be updated #656

Answered by tanius
enricoschaaf asked this question in Questions
Discussion options

You must be logged in to vote

This can be achieved with a BEFORE UPDATE trigger, called for each rows of your table. It simply has to raise an exception if the UPDATE statement tries to modify the "forbidden" columns. Compared to some of the other options, there is full UI support for this solution as of now:

  1. Under "Database → Functions", create a function users_columns_updateable with this function body (assuming pgsql is set as your function language):

    BEGIN
      IF NEW.roles <> OLD.roles THEN
        RAISE EXCEPTION 'changing "roles" is not allowed';
      END IF;
    
      RETURN NEW;
    END;
    
  2. Under "Database → Triggers", create a new trigger columns_updateable that fires before UPDATE statements, for each row, and select the abov…

Replies: 10 comments 18 replies

Comment options

You must be logged in to vote
2 replies
@christopherreay
Comment options

@steve-chavez
Comment options

Comment options

You must be logged in to vote
1 reply
@mtte
Comment options

Comment options

You must be logged in to vote
3 replies
@MentalGear
Comment options

@steve-chavez
Comment options

@arnoson
Comment options

Answer selected by steve-chavez
Comment options

You must be logged in to vote
2 replies
@MentalGear
Comment options

@z-x
Comment options

Comment options

You must be logged in to vote
6 replies
@aboveyunhai
Comment options

@TomExMachina
Comment options

@devhandler
Comment options

@NiklasPor
Comment options

@wave-light
Comment options

Comment options

You must be logged in to vote
2 replies
@arinmirza
Comment options

@kamerat
Comment options

Comment options

You must be logged in to vote
2 replies
@devhandler
Comment options

@lt692
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet