From: | Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com> |
---|---|
To: | iepug(at)postgresql(dot)org |
Subject: | Culturally aware initcap |
Date: | 2010-04-19 23:06:21 |
Message-ID: | o2qdb471ace1004191606x5985fce6jf8d3f437b46274a2@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | iepug |
I wrote this little utility function that someone might find useful:
CREATE OR REPLACE FUNCTION cul_initcap(input_val text) RETURNS text AS
$function_body$
-- culturally aware initcap, written by Peter Geoghegan ("sternocera")
-- use this in place of initcap, and strings with possessive
apostrophes are correctly initcap'd
-- (e.g. "PETER'S string" becomes "Peter's String", not "Peter'S String")
-- It still initcaps Irish names like O'Shaughnessy correctly
SELECT regexp_replace(initcap($1), $$'S([^[:upper:][:lower:]]|$)$$,
$$'s\1$$, 'g');
$function_body$
LANGUAGE 'sql' IMMUTABLE;
I'm going to put it on the wiki, because it's a problem that's come up
a good few times on IRC, and it ought to have a template solution.
Regards,
Peter Geoghegan
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond O'Donnell | 2010-04-19 23:11:25 | Re: Culturally aware initcap |
Previous Message | Alex Markelov | 2010-04-12 17:20:59 | Re: What's up? |