Skip to content

Instantly share code, notes, and snippets.

@ik5
Created January 6, 2022 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/48af286a34b7bb4b99e69fa118a7515d to your computer and use it in GitHub Desktop.
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
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