Last active
December 21, 2015 16:59
-
-
Save yancya/6337654 to your computer and use it in GitHub Desktop.
PostgreSQL で配列と配列の差集合の配列を返す関数
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
-- | |
-- SELECT array_minus(array[1,2,3], array[1,2]); -> {3} | |
-- | |
CREATE OR REPLACE FUNCTION pg_temp.array_minus (anyarray, anyarray) RETURNS anyarray AS | |
$$ | |
SELECT array_agg(t.unnest) | |
FROM ((SELECT UNNEST($1)) | |
EXCEPT | |
(SELECT UNNEST($2))) | |
AS t; | |
$$ | |
LANGUAGE SQL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment