SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE OR REPLACE FUNCTION count_btween_timestamps(tbl text, start_ts TIMESTAMP WITHOUT TIME ZONE, end_ts TIMESTAMP WITHOUT TIME ZONE) RETURNS int AS $$ declare count int; begin EXECUTE format('SELECT count(*) FROM %1$s WHERE inserted_at > ''%2$s'' ::timestamp and inserted_at < ''%3$s'' ::timestamp', tbl,start_ts, end_ts) INTO count; RETURN count; end; $$ LANGUAGE PLPGSQL; select * FROM count_btween_timestamps('ride'::text, '2022-04-01'::timestamp, '2022-05-01'::timestamp); SELECT prosrc FROM pg_proc WHERE proname = 'count_btween_timestamps';
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear