From: Sebastian Harl Date: Wed, 14 Nov 2012 18:36:00 +0000 (+0100) Subject: collectd_insert.sql: Let values_update_childs() return table names. X-Git-Tag: collectd-5.2.0~13^2~12 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=dbb9598a52ed065012feebf1b58a1e18a4a21f78;p=collectd.git collectd_insert.sql: Let values_update_childs() return table names. The function will now return a set of the names of child tables that have been created. --- diff --git a/contrib/postgresql/collectd_insert.sql b/contrib/postgresql/collectd_insert.sql index 7ccd909a..778de864 100644 --- a/contrib/postgresql/collectd_insert.sql +++ b/contrib/postgresql/collectd_insert.sql @@ -117,7 +117,7 @@ CREATE OR REPLACE VIEW collectd -- the tables for the next couple of days CREATE OR REPLACE FUNCTION values_update_childs( integer - ) RETURNS integer + ) RETURNS SETOF text LANGUAGE plpgsql AS $_$ DECLARE @@ -125,14 +125,12 @@ DECLARE cur_day date; next_day date; i integer; - n integer; BEGIN IF days < 1 THEN RAISE EXCEPTION 'Cannot have negative number of days'; END IF; i := 0; - n := 0; LOOP EXIT WHEN i > days; @@ -150,8 +148,7 @@ BEGIN CONTINUE; END; - RAISE INFO 'Created table "values$%"', cur_day; - n := n + 1; + RETURN NEXT 'values$' || cur_day::text; EXECUTE 'ALTER TABLE ONLY "values$' || cur_day || '" ADD CONSTRAINT "values_' || cur_day || '_pkey" @@ -160,7 +157,7 @@ BEGIN ADD CONSTRAINT "values_' || cur_day || '_id_fkey" FOREIGN KEY (id) REFERENCES identifiers(id)'; END LOOP; - RETURN n; + RETURN; END; $_$;