Skip to content

Instantly share code, notes, and snippets.

@fdidron
Created June 13, 2018 03:01
Show Gist options
  • Save fdidron/dd736864c21ff6ddc777a1a337a6a216 to your computer and use it in GitHub Desktop.
Save fdidron/dd736864c21ff6ddc777a1a337a6a216 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
SELECT regexp_replace(
trim(
lower(
regexp_replace(
unaccent("value"),
E'[^\\w\\s-]',
'',
'gi'
)
)
),
E'[-\\s]+', '-', 'gi'
) FROM "normalized";
$$ LANGUAGE SQL STRICT IMMUTABLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment