Created
May 16, 2014 11:51
-
-
Save everilae/76e584e611ae9ffec2ea to your computer and use it in GitHub Desktop.
PostgreSQL PL/pgSQL array_foreach
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 function array_foreach(text, anyarray) returns anyarray as $$ | |
declare | |
funcname alias for $1; | |
vals alias for $2; | |
results alias for $0; | |
begin | |
execute format('select array_agg(s.t) from (select %I(unnest($1))) as s(t)', funcname) into results using vals; | |
return results; | |
end; | |
$$ language plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment