Skip to content

Instantly share code, notes, and snippets.

@jamesmoriarty
Created May 29, 2012 22:30
Show Gist options
  • Save jamesmoriarty/2831182 to your computer and use it in GitHub Desktop.
Save jamesmoriarty/2831182 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION calculate_dialup(
hours real,
service_dialup_id int
) RETURNS real as $$
DECLARE
dialup service_dialups%ROWTYPE;
excess_usage_charge real := 0;
BEGIN
SELECT * INTO dialup FROM service_dialups WHERE id = service_dialup_id;
-- ...
END
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION calculate_dialup(
hours real,
dialup_monthly_charge real,
dialup_uncharged real,
dialup_excess_usage_charge real
) RETURNS real as $$
DECLARE
excess_usage_charge real := 0;
BEGIN
-- ...
END
$$ LANGUAGE plpgsql STABLE;
draft=# SELECT * FROM pg_stat_user_functions;
funcid | schemaname | funcname | calls | total_time | self_time
--------+------------+--------------------------------------+-------+------------+-----------
423124 | public | calculate_dialup | 4265 | 292042 | 291912
423129 | public | calculate_local_calling | 4265 | 2643 | 2643
draft=# SELECT * FROM pg_stat_user_functions;
funcid | schemaname | funcname | calls | total_time | self_time
--------+------------+--------------------------------------+-------+------------+-----------
423124 | public | calculate_dialup | 4265 | 222 | 222
423129 | public | calculate_local_calling | 4265 | 2400 | 2400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment