title: Using PostgreSQL row level security (RLS) policies with current_setting() function
body: <p>I've applied RLS policy to the &quot;users&quot; table and expect only records with <code>tenant_id=2</code> to be retrieve:</p>
  <pre><code>CREATE TABLE &quot;users&quot; (&quot;name&quot; text UNIQUE NOT NULL, &quot;tenant_id&quot; int NOT NULL DEFAULT current_setting('app.current_tenant')::int);
  
  --Enable Row Security Policies
  ALTER TABLE users ENABLE ROW LEVEL SECURITY;
  ALTER TABLE users FORCE ROW LEVEL SECURITY;
  CREATE POLICY tenant_isolation_policy ON users USING (tenant_id = current_setting('app.current_tenant')::int);
  
  --Set &quot;111&quot; as the current tenant.
  SET app.current_tenant TO 1;
  INSERT INTO users VALUES ('admin');
  INSERT INTO users VALUES ('bob');
  
  --Set &quot;222&quot; as the current tenant.
  SET app.current_tenant TO 2;
  INSERT INTO users VALUES ('alice');
  
  --Data output
  SELECT * FROM users;
  </code></pre>
  <p>But I get all users in the result:</p>
  <pre><code>name    tenant_id
  admin   1
  bob     1
  alice   2
  </code></pre>
  <p>Why is this happening?</p>
  <p>Here is the dbFiddle of what I am stuck with:
  <a href="https://www.db-fiddle.com/f/iFktvVsDNYKggUNT2oDJBV/0" rel="nofollow noreferrer">https://www.db-fiddle.com/f/iFktvVsDNYKggUNT2oDJBV/0</a></p>