Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
example on how to use postgresql to find the biggest prefix from content at a table
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