Changeset a22c5e518153d427a2ead233822c631e036c22ba for sql
- Timestamp:
- 10/23/09 14:56:37 (4 years ago)
- git-parent:
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sql/sprocs/stratcon.fetch_dataset.sql
rf805e6b ra22c5e5 42 42 v_start_adj timestamptz; 43 43 v_end_adj timestamptz; 44 v_rollup text; 44 45 v_l_rollup_row stratcon.metric_numeric_rollup_segment%rowtype; 45 46 v_rollup_row stratcon.metric_numeric_rollup_segment%rowtype; … … 53 54 END IF; 54 55 56 select array_to_string(regexp_matches (v_target.tablename, '_([^_]+)$'),'') into v_rollup; 57 55 58 -- round start and end timestamps to period precision (i.e. to 5 minutes, or 1 hour, or ...) 56 59 v_start_adj := ( 'epoch'::timestamp + v_target.period * floor( extract('epoch' from in_start_time) / v_target.epoch_period ) ) AT TIME ZONE 'UTC'; … … 59 62 -- build sql using placeholders ([something]) to make it more readable than using ' || ... || ' all the time. 60 63 v_sql_subtable := $SQL$ 61 select * 62 from stratcon.[tablename] 63 where 64 sid = [in_sid] 65 and "name" = [in_name] 66 and rollup_time between [v_start_adj]::timestamp AND [v_end_adj]::timestamp 64 SELECT * 65 FROM stratcon.unroll_metric_numeric( 66 [in_sid], 67 [in_name], 68 [v_start_adj]::timestamp, 69 [v_end_adj]::timestamp, 70 [v_rollup] 71 ) 67 72 $SQL$; 68 IF v_target.tablename = 'metric_numeric_rollup_5m' THEN69 70 v_sql_subtable := $SQL$71 SELECT *72 FROM stratcon.unroll_metric_numeric_5m(73 [in_sid],74 [in_name],75 [v_start_adj]::timestamp,76 [v_end_adj]::timestamp77 )78 $SQL$;79 80 END IF;81 73 82 74 v_sql := $SQL$ … … 104 96 v_sql := replace( v_sql, '[nperiods]', v_target.nperiods::TEXT ); 105 97 v_sql := replace( v_sql, '[tablename]', quote_ident( v_target.tablename ) ); 98 v_sql := replace( v_sql, '[v_rollup]', quote_literal( v_rollup ) ); 106 99 107 100 FOR v_rollup_row IN EXECUTE v_sql LOOP
