Skip to content

Instantly share code, notes, and snippets.

@langpavel langpavel/uaccent.sql
Last active Jun 7, 2019

Embed
What would you like to do?
PostgreSQL URL slug usable for indices
/**
* original unaccent function isn't usable for indices
*/
CREATE OR REPLACE FUNCTION uaccent(text) RETURNS text AS
$uaccent$
SELECT unaccent('unaccent',$1::text);
$uaccent$ LANGUAGE sql IMMUTABLE;
CREATE OR REPLACE FUNCTION url_slug(text) RETURNS text AS
$url_slug$
SELECT trim(both '-' from
regexp_replace(
unaccent('unaccent', lower($1::text)),
'[^a-z0-9]+', '-', 'g'
)
);
$url_slug$ LANGUAGE sql IMMUTABLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.