Convert the input string to a lowercase, hyphen-separated, URL-safe slug.
SLUGIFY(str)
## Overview Converts the input string to a URL-safe slug: lowercase ASCII letters and digits separated by single hyphens. Accented characters are normalized to their ASCII equivalents (via the same logic as REMOVE_ACCENTS), then every run of non-alphanumeric characters is replaced with a single hyphen, and leading/trailing hyphens are stripped. ## Behavior - Returns NULL if the input is NULL. - Empty input (or input that reduces to only separators) returns an empty string. - Lowercases ASCII letters. - Strips diacritics from common Latin scripts. - Collapses runs of non-alphanumeric characters into a single hyphen. - Removes leading and trailing hyphens. - Deterministic and side effect free. ## Compatibility - Matches the PG-compat SLUGIFY semantics used by blogging and CMS toolchains.
| Name | Type | Description |
|---|---|---|
str | Specifies the input string. Accents are stripped, non-alphanumerics become hyphens, and the result is lowercased. |
-- Basic title to slug
SELECT SLUGIFY('Hello World!'); -- 'hello-world'
-- Handle special characters and repeated separators
SELECT SLUGIFY('Product: 50% Off!'); -- 'product-50-off'
-- Remove accents before slugifying
SELECT SLUGIFY('Cafe\u0301 Cre\u0300me'); -- 'cafe-creme'
-- Generate URL-safe identifiers for articles
SELECT article_id, SLUGIFY(title) AS url_slug
FROM cms.catalog.articles;
-- NULL propagation
SELECT SLUGIFY(NULL); -- NULL