5 ms·
result := array_append(result, ('num=>' || i)::HSTORE); Yeah, I've never read a line of PLPGSQL before this, but I can tell by the assignment operator := that
by kyllo 13y ago
result := array_append(result, ('num=>' || i)::HSTORE);
Yeah, I've never read a line of PLPGSQL before this, but I can tell by the assignment operator := that this is obviously creating a copy of the array every time you add an element to the array. This would also cause a quadratic blowup and/or a memory blowup in any other language I've heard of, not just PLPGSQL. Anyone who has taken an introductory algorithms & data structures class really should know better than to write code like this.
- ScottBurson 13y agoBut anyone who has taken a graduate-level data structures course should know how to implement functional sequences with log-time concatenation or better. There are several known techniques. So your inference is, in fact, incorrect. The assignment must make a logical copy, but this does not have to involve making a physical copy.
- kyllo 13y agoYes, but you had better be sure that's what your compiler is going to do, before writing code like `result := array_append(result, new_element)` inside a loop.