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: (view raw or whole 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
	-- 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');

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.

Peter Geoghegan


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-2015 The PostgreSQL Global Development Group