Created
December 1, 2017 12:15
-
-
Save nwalker/a8e43736bc43451c8e66a2ef159c9805 to your computer and use it in GitHub Desktop.
PlPython3 longest common prefix aggregate
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
| drop function lcp_text(text,text) cascade; | |
| create function lcp_text(acc text, b text) | |
| returns text as $$ | |
| import itertools as i | |
| if acc is None: | |
| return b | |
| return ''.join(list( | |
| a for (a, _) | |
| in i.takewhile(lambda x: x[0] == x[1], zip(acc, b)))) | |
| $$ language plpython3u; | |
| create aggregate LCP(text) ( | |
| stype = text, | |
| sfunc = lcp_text | |
| ); | |
| select lcp_text('aa', 'aaad'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment