Currently I have a simple schema, a
sites
table and an items
table.
Sites
own many items
, items
has a siteId
column to store the reference of the site which owns it.
I'd like to be able to enforce a condition when querying items
, meaning returning an error if it is not queried with a siteId
- in practice:
- select * from items
would fail
- select * from items where siteId = 1
would succeed, albeit a site record with id 1 exists
This can easily be achieved on an application level.
I recently started investigating further into row level policies, roles, functions, etc… which I found very interesting as they enable lower level setups. That is, I'm still new about it and lack understanding/knowledge. I was wondering if the use case described above could simply be solved within SQL (via a combination of policies, functions, etc… or any other Postgres builtin tools)?
Asked by Ben
(179 rep)
Feb 15, 2018, 10:31 AM
Last activity: Feb 15, 2018, 11:43 AM
Last activity: Feb 15, 2018, 11:43 AM