Created
January 6, 2022 07:10
-
-
Save ik5/48af286a34b7bb4b99e69fa118a7515d to your computer and use it in GitHub Desktop.
example on how to use postgresql to find the biggest prefix from content at a table
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
CREATE OR REPLACE FUNCTION public.prefixes(character varying) RETURNS character varying[] | |
LANGUAGE sql IMMUTABLE | |
AS $_$ | |
SELECT ARRAY(SELECT substring($1 FROM 1 FOR i) | |
FROM generate_series(1, GREATEST(length($1))) g(i))::varchar[]; | |
$_$ | |
SELECT MAX(prefix) FROM MY_TABLE WHERE prefix=ANY(content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment