Skip site navigation (1) Skip section navigation (2)

Culturally aware initcap

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 (view raw or flat)
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

Responses

iepug by date

Next:From: Raymond O'DonnellDate: 2010-04-19 23:11:25
Subject: Re: Culturally aware initcap
Previous:From: Alex MarkelovDate: 2010-04-12 17:20:59
Subject: Re: What's up?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group