pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Can you make a simple view non-updatable?
7+ messages / 5 participants
[nested] [flat]

* Can you make a simple view non-updatable?
@ 2018-06-08 08:38 Ryan Murphy <ryanfmurphy@gmail.com>
  2018-06-08 09:04 ` Re: Can you make a simple view non-updatable? Thiemo Kellner <thiemo@gelassene-pferde.biz>
  2018-06-08 13:27 ` Re: Can you make a simple view non-updatable? Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 2 replies; 7+ messages in thread

From: Ryan Murphy @ 2018-06-08 08:38 UTC (permalink / raw)
  To: pgsql-general

Hello.

I enjoy using VIEWs.  Often my views are updatable, either automatically
(due to being a simple 1-table view, or due to a TRIGGER).  Sometimes they
are meant to be just read-only.

Is there any way to set a VIEW to be read-only -- specifically, can I do
this for a view that is automatically updatable due to being simple?

The reason I want this:  It will help me encode into my schema the
distinction between views that are supposed to behave like full-fledged
"subtypes" of a larger relation and need to be updatable, vs those that are
merely a report / literally just a "view".

Thanks!
Ryan

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Can you make a simple view non-updatable?
  2018-06-08 08:38 Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
@ 2018-06-08 09:04 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
  2018-06-08 09:17   ` Re: Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Thiemo Kellner @ 2018-06-08 09:04 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Zitat von Ryan Murphy <ryanfmurphy@gmail.com>:

> Is there any way to set a VIEW to be read-only -- specifically, can I do
> this for a view that is automatically updatable due to being simple?

Without saying anything about if this is directly possible, using  
different users with appropriate grants Comes to my mind, i. e. maybe  
it is time to overhaul the security concept.


Cheer, Thiemo

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Can you make a simple view non-updatable?
  2018-06-08 08:38 Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
  2018-06-08 09:04 ` Re: Can you make a simple view non-updatable? Thiemo Kellner <thiemo@gelassene-pferde.biz>
@ 2018-06-08 09:17   ` Ryan Murphy <ryanfmurphy@gmail.com>
  2018-06-08 09:27     ` Re: Can you make a simple view non-updatable? Ron <ronljohnsonjr@gmail.com>
  2018-06-08 10:31     ` Re: Can you make a simple view non-updatable? Thiemo Kellner, NHC Barhufpflege <thiemo.kellner@gelassene-pferde.biz>
  0 siblings, 2 replies; 7+ messages in thread

From: Ryan Murphy @ 2018-06-08 09:17 UTC (permalink / raw)
  To: Thiemo Kellner <thiemo@gelassene-pferde.biz>; +Cc: pgsql-general@lists.postgresql.org

> maybe it is time to overhaul the security concept.
>

I could see how I could revoke permissions from, say, all users that aren't
superusers to INSERT or UPDATE certain views.  However, if possible it
would be nice to get an error message about the VIEW not being updatable,
rather than a user access error, which could be misleading.

When I try to insert into a non-updatable VIEWs, I get this message:

ERROR:  cannot insert into view "test_view"
DETAIL:  Views containing GROUP BY are not automatically updatable.
HINT:  To enable inserting into the view, provide an INSTEAD OF INSERT
trigger or an unconditional ON INSERT DO INSTEAD rule.

It would be great to see something like this when trying to insert into a
simple VIEW that I had made non-updatable:

ERROR:  cannot insert into view "test_view2"
DETAIL:  This view has manually been made non-updatable.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Can you make a simple view non-updatable?
  2018-06-08 08:38 Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
  2018-06-08 09:04 ` Re: Can you make a simple view non-updatable? Thiemo Kellner <thiemo@gelassene-pferde.biz>
  2018-06-08 09:17   ` Re: Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
@ 2018-06-08 09:27     ` Ron <ronljohnsonjr@gmail.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Ron @ 2018-06-08 09:27 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org



On 06/08/2018 04:17 AM, Ryan Murphy wrote:
>
>     maybe it is time to overhaul the security concept.
>
>
> I could see how I could revoke permissions from, say, all users that 
> aren't superusers to INSERT or UPDATE certain views.  However, if possible 
> it would be nice to get an error message about the VIEW not being 
> updatable, rather than a user access error, which could be misleading.
>
> When I try to insert into a non-updatable VIEWs, I get this message:
>
> ERROR:  cannot insert into view "test_view"
> DETAIL:  Views containing GROUP BY are not automatically updatable.
> HINT:  To enable inserting into the view, provide an INSTEAD OF INSERT 
> trigger or an unconditional ON INSERT DO INSTEAD rule.
>
> It would be great to see something like this when trying to insert into a 
> simple VIEW that I had made non-updatable:
>
> ERROR:  cannot insert into view "test_view2"
> DETAIL:  This view has manually been made non-updatable.

Something like CREATE READ ONLY VIEW test_view2 AS SELECT ....

-- 
Angular momentum makes the world go 'round.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Can you make a simple view non-updatable?
  2018-06-08 08:38 Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
  2018-06-08 09:04 ` Re: Can you make a simple view non-updatable? Thiemo Kellner <thiemo@gelassene-pferde.biz>
  2018-06-08 09:17   ` Re: Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
@ 2018-06-08 10:31     ` Thiemo Kellner, NHC Barhufpflege <thiemo.kellner@gelassene-pferde.biz>
  1 sibling, 0 replies; 7+ messages in thread

From: Thiemo Kellner, NHC Barhufpflege @ 2018-06-08 10:31 UTC (permalink / raw)
  To: Ryan Murphy <ryanfmurphy@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

Zitat von Ryan Murphy <ryanfmurphy@gmail.com>:

> I could see how I could revoke permissions from, say, all users that aren't
> superusers to INSERT or UPDATE certain views.  However, if possible it
> would be nice to get an error message about the VIEW not being updatable,
> rather than a user access error, which could be misleading.

I feel it would be the other way round. If you deny something that is  
technically possible, I would be puzzled to get an error about a  
technical impossibility. If you want to stop people updating a view,  
in my opion, it is very well to tell them they are not allowed to and  
not that it isn't technically possible. So there can start a  
discussion whether they are rightfully denied to update data therein,  
instead of first discussing why it is not technically possible to  
update to find out it IS technically possible but it was actually  
denied.

> When I try to insert into a non-updatable VIEWs, I get this message:
>
> ERROR:  cannot insert into view "test_view"
> DETAIL:  Views containing GROUP BY are not automatically updatable.
> HINT:  To enable inserting into the view, provide an INSTEAD OF INSERT
> trigger or an unconditional ON INSERT DO INSTEAD rule.
>
> It would be great to see something like this when trying to insert into a
> simple VIEW that I had made non-updatable:
>
> ERROR:  cannot insert into view "test_view2"
> DETAIL:  This view has manually been made non-updatable.

You still could put a trigger on the views throwing according  
exceptions for specific users. I think I partly used that already but  
can't find the code at the moment.



-- 
+49 (0)1578-772 37 37
+41 (0)78 947 36 21
Öffentlicher PGP-Schlüssel:  
http://pgp.mit.edu/pks/lookup?op=get&search=0xCA167FB0E717AFFC

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Can you make a simple view non-updatable?
  2018-06-08 08:38 Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
@ 2018-06-08 13:27 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2018-06-13 13:23   ` Re: Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2018-06-08 13:27 UTC (permalink / raw)
  To: Ryan Murphy <ryanfmurphy@gmail.com>; pgsql-general

On 06/08/2018 01:38 AM, Ryan Murphy wrote:
> Hello.
> 
> I enjoy using VIEWs.  Often my views are updatable, either automatically 
> (due to being a simple 1-table view, or due to a TRIGGER).  Sometimes 
> they are meant to be just read-only.
> 
> Is there any way to set a VIEW to be read-only -- specifically, can I do 
> this for a view that is automatically updatable due to being simple?

Using INSTEAD OF trigger?:

create view ct_vw as select * from container;

insert into ct_vw (c_id, cdesc, cell_per, c_size, c_units) values 
('test', 'test container', 1, 2, 4);
INSERT 1836533 1


CREATE OR REPLACE FUNCTION public.vw_ro()
  RETURNS trigger
  LANGUAGE plpgsql
AS $function$
BEGIN
     RAISE NOTICE 'Read only view';
     RETURN NULL;
END;
$function$

CREATE TRIGGER ro_trg INSTEAD OF INSERT or UPDATE or DELETE ON ct_vw FOR 
EACH ROW EXECUTE  procedure vw_ro();

insert into ct_vw (c_id, cdesc, cell_per, c_size, c_units) values 
('test', 'test container', 1, 2, 4);
NOTICE:  Read only view
INSERT 0 0

update ct_vw set cell_per = 100 where c_id = '200PT';
NOTICE:  Read only view
UPDATE 0

delete from ct_vw where c_id = '200PT';
NOTICE:  Read only view
DELETE 0


> 
> The reason I want this:  It will help me encode into my schema the 
> distinction between views that are supposed to behave like full-fledged 
> "subtypes" of a larger relation and need to be updatable, vs those that 
> are merely a report / literally just a "view".
> 
> Thanks!
> Ryan


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Can you make a simple view non-updatable?
  2018-06-08 08:38 Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
  2018-06-08 13:27 ` Re: Can you make a simple view non-updatable? Adrian Klaver <adrian.klaver@aklaver.com>
@ 2018-06-13 13:23   ` Ryan Murphy <ryanfmurphy@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Ryan Murphy @ 2018-06-13 13:23 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general

On Fri, Jun 8, 2018 at 8:27 AM, Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

>
> Using INSTEAD OF trigger?:
>

Yep, that's one way.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2018-06-13 13:23 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08 08:38 Can you make a simple view non-updatable? Ryan Murphy <ryanfmurphy@gmail.com>
2018-06-08 09:04 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
2018-06-08 09:17   ` Ryan Murphy <ryanfmurphy@gmail.com>
2018-06-08 09:27     ` Ron <ronljohnsonjr@gmail.com>
2018-06-08 10:31     ` Thiemo Kellner, NHC Barhufpflege <thiemo.kellner@gelassene-pferde.biz>
2018-06-08 13:27 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-06-13 13:23   ` Ryan Murphy <ryanfmurphy@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox