Using 'new' special variable inside RLS insert policy #6824
tchief
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is a handy
new
special variable that exists in functions that return triggers, which has the record to be inserted. Sonew.name
would getname
column of row to be inserted.When creating a new RLS insert policy from UI, the whole record is 'unwrapped', so
name
could be accessed directly.However, sometimes you need more sophisticated policy and do not want to create a special function for that. In this case, alternative to
new.name
would betable.name
wheretable
is name of table you are writing policy for.Faced this once, was not sure whether this behavior and workaround above was a bug or a feature.
Thanks to @alaister decided to double check and share.
insert-policy-new-variable.mp4
Beta Was this translation helpful? Give feedback.
All reactions