SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
/* CREATE TABLE Towns ( id SERIAL UNIQUE NOT NULL, code VARCHAR(10) NOT NULL, -- not unique article TEXT, name TEXT NOT NULL, -- not unique department VARCHAR(4) NOT NULL REFERENCES Departments (code), UNIQUE (code, department) ); */ Create or replace function random_string(length integer) returns text as $$ declare chars text[] := '{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}'; result text := ''; i integer := 0; begin if length < 0 then raise exception 'Given length cannot be less than 0'; end if; for i in 1..length loop result := result || chars[1+random()*(array_length(chars, 1)-1)]; end loop; return result; end; $$ language plpgsql; create table test ( id serial , s1 varchar(32) , s2 varchar(32) , s3 varchar(32) ); insert into test (s1,s2,s3) select -- random_string(50) md5(random()::text) , md5(random()::text) , md5(random()::text) from generate_series(1, 1000000); select * from test limit 3; ------------------ set max_parallel_workers_per_gather = 0; explain (analyze, buffers, timing 0) select sum(id) from test where s1 like '%e%' and s2 like '%d%' and s3 like '%f%' -- and s1 = 'aa' -- and s2 = 'bb' -- and s3 = 'cc' ;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear