Row-Level Security (RLS) allows for the management of access to individual data rows at the table level, enabling detailed access isolation. This feature lets administrators set specific rules that determine which table rows users can view or modify.
-- Order data is grouped by tenantCREATE TABLE order_details (order_id text, tenant_name text, order_detail text);ALTER TABLE order_details ENABLE ROW LEVEL SECURITY;-- Control access to only your own tenant's dataCREATE POLICY order_multi_tenant ON order_detailsUSING (tenant_name = current_user);-- Create multiple strategies, applied in combination. The relationship between multiple strategies is OR:CREATE POLICY order_update ON order_detailsFOR UPDATEUSING (tenant_name = current_user)WITH CHECK (order_id IS NOT NULL);
tacnode=> \d order_details Table "public.order_details" Column | Type | Collation | Nullable | Default--------------+------+-----------+----------+--------- order_id | text | | | tenant_name | text | | | order_detail | text | | |Policies: POLICY "order_multi_tenant" USING ((tenant_name = current_user)) POLICY "order_update" FOR UPDATE USING ((tenant_name = current_user)) WITH CHECK ((order_id IS NOT NULL))