Re: [GENERAL] Subtract one array from another, both with non-unique elements

2016-03-08 Thread Victor Yegorov
2016-03-08 15:59 GMT+02:00 Alexander Farber : > Here 1-pass version, if you have improvement suggestions, you are welcome - > My variant: CREATE OR REPLACE FUNCTION arrexcept(anyarray, anyarray) RETURNS anyarray AS $arrexcept$ SELECT array_agg(un) FROM ( SELECT

Re: [GENERAL] Subtract one array from another, both with non-unique elements

2016-03-08 Thread Alexander Farber
Here 1-pass version, if you have improvement suggestions, you are welcome - DROP FUNCTION IF EXISTS words_array_subtract(anyarray, anyarray); CREATE OR REPLACE FUNCTION words_array_subtract(from_array anyarray, remove_array anyarray) RETURNS anyarray AS $func$ DECLARE

Re: [GENERAL] Subtract one array from another, both with non-unique elements

2016-03-08 Thread Alexander Farber
Hello again, I could not find a solution neither at http://postgres.cz/wiki/Array_based_functions nor at https://github.com/JDBurnZ/postgresql-anyarray So I have written my own stored function to subtract one non-unique array from another (like swapping tiles in a word game): DROP FUNCTION IF

Re: [GENERAL] Subtract one array from another, both with non-unique elements

2016-03-06 Thread Pavel Stehule
Hi 2016-03-06 18:41 GMT+01:00 Alexander Farber : > Thank you, but shouldn't I better use FOREACH for my task? > > SQL based solution (functional based) solution can be faster and shorter. PLpgSQL is nice language, but what you can do about arrays functionally, you

Re: [GENERAL] Subtract one array from another, both with non-unique elements

2016-03-06 Thread Alexander Farber
Thank you, but shouldn't I better use FOREACH for my task? On Sun, Mar 6, 2016 at 6:34 PM, bricklen wrote: > On Sun, Mar 6, 2016 at 9:22 AM, Alexander Farber < > alexander.far...@gmail.com> wrote: > >> could someone please recommend the most efficient way subtracting >>

Re: [GENERAL] Subtract one array from another, both with non-unique elements

2016-03-06 Thread bricklen
On Sun, Mar 6, 2016 at 9:22 AM, Alexander Farber wrote: > could someone please recommend the most efficient way subtracting elements > of one array from the other in PostgreSQL 9.5? > There are quite a few examples of array functions at

[GENERAL] Subtract one array from another, both with non-unique elements

2016-03-06 Thread Alexander Farber
Hello, could someone please recommend the most efficient way subtracting elements of one array from the other in PostgreSQL 9.5? Should I create a new array or can I work on the existing one (and if the latter - will FOREACH work well when elements are removed "from under its feet"?). Both