Skip to content
Advertisement

Change values before insert into table / PostgreSQL

Ive got the following problem. I want to change some values of INSERT statement, e.g. there’s a query:

But table has also another column c. I want to check (before INSERT) value of b from the query above and depending on one’s value then set c=z but only for this specific row I’ve just inserted.

I think that some trigger can help in my problem but I’ve no idea how to do that. Any pseudocode would be appreciated.

Advertisement

Answer

It is the goog practice to restrict direct access to the table(s) for regular users. It can be done by using stored procedures and gives access rights only to them. For example (sorry for long code):

So, forget about insert into, use stored procedures :o)

PS: Note about SECURITY DEFINER option. It allows to grant access to the function without granting access to objects used inside it.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement