CREATE EXTENSION slim; CREATE EXTENSION pacs; SELECT pacs_reset_all_measures(); pacs_reset_all_measures ------------------------- (1 row) -- create a measure SELECT pacs_create_measure('A'); pacs_create_measure --------------------- (1 row) -- increment it 3 times SELECT pacs_increment_measure('A'); pacs_increment_measure ------------------------ (1 row) SELECT pacs_increment_measure('A'); pacs_increment_measure ------------------------ (1 row) SELECT pacs_increment_measure('A'); pacs_increment_measure ------------------------ (1 row) -- check measure value is 3 SELECT pacs_get_measure('A'); pacs_get_measure ------------------ 3 (1 row) -- reset the measure SELECT pacs_reset_measure('A'); pacs_reset_measure -------------------- (1 row) -- should be 0 now SELECT pacs_get_measure('A'); pacs_get_measure ------------------ 0 (1 row) -- increment again SELECT pacs_increment_measure('A'); pacs_increment_measure ------------------------ (1 row) -- should be 1 SELECT pacs_get_measure('A'); pacs_get_measure ------------------ 1 (1 row) -- and drop the measure SELECT pacs_drop_measure('A'); pacs_drop_measure ------------------- (1 row) -- get stats from pacs (empty) -- SELECT * FROM pacs_get_stats(); -- create 2 measures SELECT pacs_create_measure('B'); pacs_create_measure --------------------- (1 row) SELECT pacs_create_measure('C'); pacs_create_measure --------------------- (1 row) -- expect 2 measures -- SELECT * FROM pacs_get_stats(); -- drop one SELECT pacs_drop_measure('B'); pacs_drop_measure ------------------- (1 row) -- so result now is 1 -- SELECT * FROM pacs_get_stats(); -- -- SPECIAL CASES -- -- measure A has been dropped already. -- but it's not erroing, as expected. SELECT pacs_drop_measure('A'); pacs_drop_measure ------------------- (1 row) -- trying to get value for an inexisting measure -- should ERROR SELECT pacs_get_measure('absent'); ERROR: measure "absent" does not exist HINT: ensure the measure name is correct or $$ select create_measure('absent')$$ to create it -- reseting an inexsting measure -- but it's not erroing, as expected SELECT pacs_reset_measure('absent'); pacs_reset_measure -------------------- (1 row) -- the measure still does not exist -- so we have an error SELECT pacs_get_measure('absent'); ERROR: measure "absent" does not exist HINT: ensure the measure name is correct or $$ select create_measure('absent')$$ to create it -- however increment always create the measure if it does not exists SELECT pacs_increment_measure('absent'); pacs_increment_measure ------------------------ (1 row) -- and now we can fetch value (should be 1) SELECT pacs_get_measure('absent'); pacs_get_measure ------------------ 1 (1 row) -- and we drop the "absent" measure (yeah, it's confusing) SELECT pacs_drop_measure('absent'); pacs_drop_measure ------------------- (1 row)