0

Adding a cross-schema foreign key:

ALTER TABLE "editedArticles"
  ADD CONSTRAINT "editedArticles_articles_foreign"
  FOREIGN KEY("originalArticleId") REFERENCES "private".articles("id");

fails with:

ERROR:  42501: permission denied for table articles

even after successfully executing:

GRANT USAGE ON SCHEMA private TO postgres;
GRANT SELECT, REFERENCES ON TABLE private."articles" TO postgres;

I seem to have the same problem as asked about in this unanswered question.

For the record:

  • SELECT current_user; returns postgres
  • \du+ postgres returns Create role, Create DB, Replication, Bypass RLS

and finally:

postgres=> \dn+ private
                       List of schemas
  Name   |  Owner   |     Access privileges     | Description 
---------+----------+---------------------------+-------------
 private | postgres | postgres=UC/postgres     +| 
         |          | digest=UC/postgres       +| 
         |          | supabase_admin=U/postgres | 
(1 row)

postgres=> \z private.articles
                                     Access privileges
 Schema  |   Name   | Type  |       Access privileges       | Column privileges | Policies 
---------+----------+-------+-------------------------------+-------------------+----------
 private | articles | table | digest=arwdDxt/digest        +|                   | 
         |          |       | supabase_admin=arwdDxt/digest+|                   | 
         |          |       | postgres=r/digest             |                   | 
(1 row)

Note that postgres=r/digest only has the r (read) permission on that table, not the x (references). But why? I executed GRANT REFERENCES (as mentioned above).

1 Answer 1

2

Turns out that the command:

GRANT SELECT, REFERENCES ON TABLE private."articles" TO postgres;

returned "Success. No rows returned" when executed with my postgres user, but it actually didn't do anything! But if I executed it with the digest user (that owns the private.articles table), then it returned "GRANT" and now it works.

2
  • 2
    It looks like your client suppresses warnings. There must have been a warning WARNING: no privileges were granted for "private.articles". Commented Oct 2 at 6:19
  • @LaurenzAlbe good to know, thanks! I was using the supabase GUI. Won't make that mistake again.
    – mb21
    Commented Oct 2 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.