pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
UPDATE TRIGGER on view WAS: Re: Relation in tables
3+ messages / 3 participants
[nested] [flat]

* UPDATE TRIGGER on view WAS: Re: Relation in tables
@ 2005-02-16 20:48  Keith Worthington <keithw@narrowpathinc.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Keith Worthington @ 2005-02-16 20:48 UTC (permalink / raw)
  To: pgsql-sql; +Cc: PFC <lists@boutiquenumerique.com>

On Wed, 16 Feb 2005 19:56:25 +0100, PFC wrote
> [snip] Use UPDATE triggers on the 
> views, which in fact  write to the products table [snip]

You can DO that!?!

Are you saying that a client can DELETE or INSERT or UPDATE a view and through
a trigger you can make this happen?  Way cool.  Can you provide a simple example?

And all this time I thought that you couldn't write to a view.

Kind Regards,
Keith



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

* Re: UPDATE TRIGGER on view WAS: Re: Relation in tables
@ 2005-02-16 21:22  PFC <lists@boutiquenumerique.com>
  parent: Keith Worthington <keithw@narrowpathinc.com>
  0 siblings, 1 reply; 3+ messages in thread

From: PFC @ 2005-02-16 21:22 UTC (permalink / raw)
  To: KeithW@narrowpathinc.com; pgsql-sql



> And all this time I thought that you couldn't write to a view.

	You can't.
	But you can make it seem so you can.

	You can create an ON UPDATE/INSERT trigger on a view which intercepts the  
UPDATE/INSERT to the view (which would otherwise fail) and do whatever you  
want with it, including doing the operation on the real table.

	Search for "postgresql materialized views" for some examples.



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

* Re: UPDATE TRIGGER on view WAS: Re: Relation in tables
@ 2005-02-16 21:39  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PFC <lists@boutiquenumerique.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2005-02-16 21:39 UTC (permalink / raw)
  To: PFC <lists@boutiquenumerique.com>; +Cc: KeithW@narrowpathinc.com; pgsql-sql

PFC <lists@boutiquenumerique.com> writes:
> You can create an ON UPDATE/INSERT trigger on a view which intercepts the  
> UPDATE/INSERT to the view (which would otherwise fail) and do whatever you  
> want with it, including doing the operation on the real table.

This might work for INSERT but I really doubt it'll work for UPDATE or
DELETE.

You may be able to make it work with rules, though there are lots of
pitfalls in that approach.

			regards, tom lane



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


end of thread, other threads:[~2005-02-16 21:39 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-16 20:48 UPDATE TRIGGER on view WAS: Re: Relation in tables Keith Worthington <keithw@narrowpathinc.com>
2005-02-16 21:22 ` PFC <lists@boutiquenumerique.com>
2005-02-16 21:39   ` Tom Lane <tgl@sss.pgh.pa.us>

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