til icon indicating copy to clipboard operation
til copied to clipboard

execute format sql

Open xluffy opened this issue 4 months ago • 0 comments

do $do$      
declare      
    i int;      
begin      
    for i in 0..99 loop      
        execute format(    
            $sql$       
                create table partitioned_table_%s       
                partition of partitioned_table       
                for values from (%s) to (%s)       
            $sql$,       
            i,       
            i * 9999 + 1,       
            (i + 1) * 9999 + 1       
        );      
            
        execute format(    
            $sql$       
                insert into partitioned_table_%s       
                select generate_series(%s, %s) as id, 'data'       
            $sql$,       
            i,       
            i * 9999 + 1,       
            (i + 1) * 9999       
        );      
            
        execute format(    
            $sql$       
                create index on partitioned_table_%s (id)       
            $sql$,       
            i       
        );      
    end loop;      
end $do$;

https://postgres.ai/blog/20241003-how-does-planning-time-depend-on-number-of-partitions

xluffy avatar Oct 04 '24 06:10 xluffy