create policy statement USING clause - Mailing list pgsql-general

From Mark Phillips
Subject create policy statement USING clause
Date
Msg-id 054FBFBF-C87C-4C3C-B6F5-D5C09E6A7F1A@mophilly.com
Whole thread Raw
Responses Re: create policy statement USING clause
List pgsql-general
PostgreSQL 12
Given a table “customer” with a column “deadfiled” of the type boolean. The column deadfiled is used to indicate that a
rowis “in the trash bin”. The app has a window that lists the contents of the “trash bin”, which any rows with
deadfiled= true. Row so marked should be excluded from views and queries in all other cases when the current user has
therole “app_user". 

I thought I could use row level security (RLS) to filter out all the deadfiled rows.

ALTER TABLE customer ENABLE ROW LEVEL SECURITY;
CREATE POLICY filter_customer_deadfiled
    ON public.customer
    FOR SELECT
    TO app_staff
    USING ( NOT deadfiled );

However, that did not work as desired. I have read through a dozen articles and posts online but haven’t figured out
theUSING clause. To my surprise, this worked: 
CREATE POLICY customer_deadfiled
ON public.customer
AS PERMISSIVE
FOR SELECT
TO prm_staff
USING (coalesce(deadfiled,false)=false);

So my question is specifically about the USING clause, but also more broadly about this attempted application of RLS.

Links and advice accepted with gratitude.

Mark


pgsql-general by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Duplicate key error
Next
From: "JOLAPARA Urvi (SAFRAN)"
Date:
Subject: RE: postgresql-17.0-1 Application - silent installation Issue