Remove emojis and symbol characters in SQL
Slack-style names and comments full of 🎉 break fixed-width exports and old clients. Remove the pictograph ranges.
The task
Emoji live in defined Unicode blocks. PostgreSQL regex escapes \Uhhhhhhhh (8 hex digits) and \uhhhh (4 hex digits) name code points, so whole blocks can be matched and deleted.
The snippet
Written for PostgreSQL. Versions for MySQL and Oracle are under Variations.
SELECT regexp_replace(display_text, '[\U0001F000-\U0001FAFF\u2600-\u27BF\uFE0F]', '', 'g') AS clean_text
FROM comments;
它的運作方式
The pattern matches the emoji and pictograph blocks (1F000-1FAFF), dingbats and misc symbols (2600-27BF) and the variation selector FE0F, deleting every match. Extend or trim the ranges to match what your data actually contains; new emoji keep moving the upper bound.
Variations
Oracle (AL32UTF8): code points built with UNISTR surrogate pairs
OracleSELECT REGEXP_REPLACE(display_text,
'[' || UNISTR('\D83C\DC00') || '-' || UNISTR('\D83E\DEFF')
|| UNISTR('\2600') || '-' || UNISTR('\27BF') || UNISTR('\FE0F') || ']', '') AS clean_text
FROM comments;
MySQL 8: ICU regex with code-point escapes
MySQLSELECT REGEXP_REPLACE(display_text, '[\\x{1F000}-\\x{1FAFF}\\x{2600}-\\x{27BF}\\x{FE0F}]', '') AS clean_text
FROM comments;
Questions that come up
What about SQL Server?
SQL Server 2025 adds REGEXP_REPLACE, so a character-class pattern works there. On 2022 and older there is no regex: chain REPLACE for the specific emoji you care about, or clean the text once in application code or an ETL step rather than in every query.
Keep reading
Related on SQLly
Run these with autocomplete that knows your tables
SQLly is a native SQL workbench for macOS, Windows and Linux. Paste a snippet into a live connection and you get schema-aware IntelliSense, a plan viewer and guards against unsafe edits.