Created
November 5, 2022 02:29
-
-
Save veer66/3849c6189f76498a3ea63fffed45f6a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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