finki-main
main
|
Last change
on this file since 33517cc was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago |
|
Project Handcraft Marketplace
|
-
Property mode
set to
100644
|
|
File size:
646 bytes
|
| Line | |
|---|
| 1 | CREATE OR REPLACE FUNCTION initialize_employee_statistics()
|
|---|
| 2 | RETURNS TRIGGER
|
|---|
| 3 | LANGUAGE plpgsql
|
|---|
| 4 | AS $$
|
|---|
| 5 | BEGIN
|
|---|
| 6 | /*
|
|---|
| 7 | * The employee is created first.
|
|---|
| 8 | * Work statistics can be initialized when
|
|---|
| 9 | * the employee is assigned to a store.
|
|---|
| 10 | * The actual store assignment should be handled
|
|---|
| 11 | * through works_in_store. */
|
|---|
| 12 | INSERT INTO worked (
|
|---|
| 13 | employee_id,
|
|---|
| 14 | total_working_hours,
|
|---|
| 15 | total_wage
|
|---|
| 16 | )
|
|---|
| 17 | VALUES (
|
|---|
| 18 | NEW.id,
|
|---|
| 19 | 0,
|
|---|
| 20 | 0
|
|---|
| 21 | );
|
|---|
| 22 | RETURN NEW;
|
|---|
| 23 | END;
|
|---|
| 24 | $$;
|
|---|
| 25 |
|
|---|
| 26 | CREATE TRIGGER trg_initialize_employee_statistics
|
|---|
| 27 | AFTER INSERT
|
|---|
| 28 | ON employees
|
|---|
| 29 | FOR EACH ROW
|
|---|
| 30 | EXECUTE FUNCTION initialize_employee_statistics();
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.