Skip to content

Instantly share code, notes, and snippets.

@veer66
Created November 5, 2022 02:29
Show Gist options
  • Save veer66/3849c6189f76498a3ea63fffed45f6a6 to your computer and use it in GitHub Desktop.
Save veer66/3849c6189f76498a3ea63fffed45f6a6 to your computer and use it in GitHub Desktop.
postgres=# CREATE TABLE citizen (name text);
CREATE TABLE
postgres=# INSERT INTO citizen VALUES ('เเซม');
INSERT 0 1
postgres=# SELECT name FROM citizen WHERE name = 'แซม';
name
------
(0 rows)
postgres=# CREATE OR REPLACE FUNCTION normalize_thai_name(name text) RETURNS text AS $$
BEGIN
RETURN REGEXP_REPLACE(name, 'เเ', 'แ', 'g');
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# UPDATE citizen SET name = normalize_thai_name(name);
UPDATE 1
postgres=# SELECT name FROM citizen WHERE name = 'แซม'; name
------
แซม
(1 row)
postgres=# SELECT name FROM citizen WHERE name = normalize_thai_name('แซม'); name
------
แซม
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment