Skip to main content
camelAI Legacy Product — This documentation covers camelAI’s embedded analytics offering, which is no longer being actively developed. We are migrating existing customers to the new camelAI platform. For the current product, visit camelAI.
PostgreSQL provides native row-level security (RLS) support that integrates seamlessly with Camel. Using session variables, you can create dynamic, per-user data access policies.

How Camel Sets the UID

For every query executed through Camel, the system automatically sets a session variable:
This variable is available throughout the query execution and can be referenced in your RLS policies.

Setting Up RLS

Step 1: Enable RLS on Your Table

First, enable row-level security on the tables you want to protect:
Once RLS is enabled, the table will deny all access by default unless you create policies to grant access.

Step 2: Create an RLS Policy

Create a policy that uses the camel.uid session variable to filter rows:
This policy ensures users can only see rows where the user_id column matches their uid.

Complete Example: User Orders

Let’s implement RLS for an e-commerce scenario where users should only see their own orders.

1. Create the Orders Table

2. Enable RLS

3. Create the Policy

4. Grant Permissions

Testing Your Policies

You can test your RLS policies directly in PostgreSQL:

Troubleshooting

Users See No Data

  • Verify the camel.uid is being set correctly
  • Check that your policy logic is correct
  • Ensure the user has the necessary table permissions

Performance Issues

  • Check if filter columns are indexed
  • Analyze query plans for inefficient policy checks

Learn More

For assistance with PostgreSQL RLS implementation, contact support@camelai.com.