Created
July 27, 2020 16:07
-
-
Save pstef/403a382771a6e47e04659113ba4ca389 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
INSERT INTO x_y | |
SELECT l.x_id, unnest(array_positions) - 1 | |
FROM ( | |
SELECT x_y.x_id, bit_or(1 << y.id) AS yids | |
FROM x_y | |
GROUP BY x_y.x_id | |
HAVING count(*) <> (SELECT count(*) FROM y) | |
) AS l, | |
reverse(((SELECT bit_or(1 << y.id) FROM y) # l.yids)::bit(64)::text), | |
string_to_array(reverse, ''), | |
array_positions(string_to_array, '1'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment