SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TYPE ab AS ( a int, b int ); CREATE FUNCTION ab(a int, b int) RETURNS ab LANGUAGE SQL AS $$ SELECT row(least(a,b), greatest(a,b))::ab $$; CREATE TABLE tbl(id int, a int, b int); -- Test data INSERT INTO tbl SELECT g, 2*g, 3*g FROM generate_series (1,10000,1) g; CREATE INDEX ON tbl (ab(a,b)); ANALYZE tbl; -- EXPLAIN SELECT * FROM tbl WHERE ab(a,b) = ab(1,2); EXPLAIN SELECT * FROM tbl WHERE ab(a,b) = ab(2,1);

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear