Re: Clarification on RLS policy - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Clarification on RLS policy
Date
Msg-id 8b745873-f008-41ec-b58e-4b167e266b29@aklaver.com
Whole thread Raw
In response to Re: Clarification on RLS policy  (Vydehi Ganti <rayudugs@gmail.com>)
List pgsql-general
On 4/25/25 06:01, Vydehi Ganti wrote:
> This is my Scenario:
> 

> *Can you please guide how to achieve this?*
> 
> CREATE OR REPLACE FUNCTION one.get_country(
> powner name,
> ptable_name name)
>      RETURNS character varying
> LANGUAGE 'plpgsql'

> 
> For the below policy statement it created the policy but i cant call that
> CREATE POLICY "Codebase_Filter"
>      ON one.activity
>      FOR SELECT
>      TO one
>      USING (one.get_country('one','activity'));

The core of the issue you are getting is that this from the function:

RETURNS character varying

is not going to work here:

USING (one.get_country('one','activity'))

as what USING will see is a string not the evaluation of 1=1 hence the 
error you get:

ERROR: invalid input syntax for type boolean: "1=1" CONTEXT: PL/pgSQL 
function function name(name,name) while casting return value to 
function's return type



-- 
Adrian Klaver
adrian.klaver@aklaver.com




pgsql-general by date:

Previous
From: Achilleas Mantzios - cloud
Date:
Subject: Re: replication
Next
From: Marc Millas
Date:
Subject: Re: shared buffers