mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-18 18:44:06 +08:00
Simplify trigger example, per Mark Kirkwood.
This commit is contained in:
parent
2c1abfd979
commit
893c66de69
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.56 2005/01/14 01:16:22 tgl Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.57 2005/01/15 03:38:44 tgl Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<chapter id="plpgsql">
|
<chapter id="plpgsql">
|
||||||
@ -2787,17 +2787,12 @@ CREATE OR REPLACE FUNCTION maint_sales_summary_bytime() RETURNS TRIGGER AS $main
|
|||||||
amount_sold,
|
amount_sold,
|
||||||
units_sold,
|
units_sold,
|
||||||
amount_cost)
|
amount_cost)
|
||||||
SELECT f.time_key,
|
VALUES (
|
||||||
sum(f.amount_sold),
|
delta_time_key,
|
||||||
sum(f.units_sold),
|
delta_amount_sold,
|
||||||
sum(f.amount_cost)
|
delta_units_sold,
|
||||||
FROM sales_fact f
|
delta_amount_cost
|
||||||
WHERE f.time_key = delta_time_key
|
);
|
||||||
GROUP BY f.time_key;
|
|
||||||
-- This query can potentially be very expensive if the trigger
|
|
||||||
-- is created on sales_fact without the time_key indexes.
|
|
||||||
-- Some care is needed to ensure that this situation does
|
|
||||||
-- *not* occur.
|
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
--
|
--
|
||||||
-- Catch race condition when two transactions are adding data
|
-- Catch race condition when two transactions are adding data
|
||||||
|
Loading…
Reference in New Issue
Block a user