Did you create the view after granting the privileges to readonlyuser
?
If so, it is not entitled to the same rights as other views. This is due to the meaning of GRANT... ON
which is "on view that exist." Permissions are kept on the item in PostgreSQL. All of an object's permissions are lost if it is dropped. Even if you subsequently create an object with the same name, it will still be distinct and have the default rights since it is a separate object.
I tried with below query, and it worked for me:
--Create view
CREATE VIEW pulic.”demov” AS SELECT * FROM demotb;
--Grant select on view to user
GRANT SELECT ON pulic.”demov” TO readonly;
After this login with database with this readonly
user and try to select the view.
To include views, you create in the future, you can use:
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonlyuser;