Database Reference
In-Depth Information
QUERY PLAN
-----------------------------------------------------------------------------------
Seq Scan on public.events (cost=0.00..1.04 rows=1 width=57)
Output: event _ id, title, starts, colors
Filter: ((events.venue _ id IS NULL) AND ((events.title)::text ~~ '%Day%'::text))
psql client
Results
SQL
String
postgres server
Converts an SQL
string into a
Query Tree
Modiies the
Query Tree based
on Rules
Where the query
is optimized before
execution
(New)
Query
Tree
Query
Tree
Parser
Rewrite
Planner
Execution
Query Trees
Rules
User Deined
Views
Abbildung 5: Wie SQL bei PostgreSQL ausgeführt wird
Um also Updates in unserem holidays -View vornehmen zu können, müssen
wir eine Regel ( RULE ) entwickeln, die Postgres anweist, was bei einem UPDA-
TE zu tun ist. Unsere Regel fängt Updates des holidays -Views ab und führt
dieses Update dann über events aus, wobei es die Werte aus den Pseudore-
lationen NEW und OLD abruft. NEW dient funktional als Relation mit den von
uns gesetzten Werten, während OLD die alten Werte enthält.
postgres/create_rule.sql
CREATE RULE update _ holidays AS ON UPDATE TO holidays DO INSTEAD
UPDATE events
SET title = NEW.name,
starts = NEW. date ,
colors = NEW.colors
WHERE title = OLD.name;
 
Search WWH ::




Custom Search