SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- SELECT * -- FROM pg_type; CREATE OR REPLACE FUNCTION f_merge_ranges(oid, text, text) RETURNS text IMMUTABLE STRICT LANGUAGE plpgsql AS $$ DECLARE raw_range text; merged_ranges text; BEGIN IF $1 = 23 THEN raw_range := 'int4range(' || $2 || ', ' || $3 || ')'; ELSIF $1 = 1082 THEN raw_range := 'daterange(' || quote_literal($2) || ', ' || quote_literal($3) || ')'; ELSE RAISE ''; END IF; EXECUTE 'SELECT ' || raw_range || '::text;' INTO merged_ranges; RETURN merged_ranges; END; $$; -- SELECT f_merge_ranges(1082, '2022-01-01', '2022-02-01'); EXPLAIN ANALYZE SELECT 1 FROM generate_series(1, 200000) s WHERE CASE WHEN s >= 30000 AND s < 50000 THEN TRUE WHEN s >= 50000 AND s < 70000 THEN TRUE WHEN s >= 70000 AND s < 90000 THEN TRUE ELSE FALSE END -- WHERE s <@ int4range(30000, 90000);

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear