Last active
January 26, 2017 15:40
-
-
Save slitayem/225a9a4da1db3d81660cca518a4d773e to your computer and use it in GitHub Desktop.
[Postgresql] Test array update efficiency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$ | |
begin | |
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim)); | |
end | |
$BODY$ LANGUAGE plpgsql; | |
CREATE EXTENSION pgcrypto; | |
CREATE TABLE test_table as select id, md5(random()::text) || id as name, random_int_array(500000, 100, 10000) as arr, gen_random_uuid() uid from generate_Series(1,3) id | |
; | |
\timing | |
update test_table set arr=arr[10:array_length(arr,1)]; | |
--- get only last two elements from array | |
select arr[array_upper(arr, 1) -(2 - 1):array_upper(arr, 1)] from test_table; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment