Re: Clarification on RLS policy

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Vydehi Ganti <rayudugs(at)gmail(dot)com>, Dominique Devienne <ddevienne(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Clarification on RLS policy
Date: 2025-04-25 15:13:49
Message-ID: 8b745873-f008-41ec-b58e-4b167e266b29@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marc Millas 2025-04-25 16:13:14 Re: shared buffers
Previous Message Achilleas Mantzios - cloud 2025-04-25 14:19:58 Re: replication