Last active
January 18, 2016 01:58
-
-
Save ianthrive/6721e6428a0dfd3990bc to your computer and use it in GitHub Desktop.
This file contains 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 diff_elements(anyarray, anyarray) | |
returns anyarray language sql immutable as $$ | |
select array( | |
select unnest($2) | |
except | |
select unnest($1) | |
);$$; | |
create operator - ( | |
procedure = diff_elements, | |
leftarg=anyarray, | |
rightarg=anyarray | |
); | |
=# select array['a', 'n', 'z'] - array['n', 'z', 'd', 'e']; | |
?column? | |
---------- | |
{d,e} | |
(1 row) | |
=# select array[1, 5, 6] - array[5, 6, 23, 64]; | |
?column? | |
---------- | |
{23,64} | |
(1 row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment