I have a simple table in PostgreSQL called keywords with a simple text field called name. I want to convert all names of keywords in first letter uppercase. Is there a way t
The initcap function capitalizes letters after special characters (dashes, apostrophes, etc). I only want to capitalize after a space.
Similar to Denis' answer, this function will convert the first letter of every word (separated by a space)
CREATE OR REPLACE FUNCTION titlecase(instr varchar) RETURNS varchar AS $$
DECLARE
strarray varchar[] := string_to_array(inStr, ' ');
outstrarray varchar[];
word varchar;
BEGIN
FOREACH word IN ARRAY strarray
LOOP
outstrarray := array_append(outstrarray, (upper(left(word,1))::varchar ||
lower(right(word,-1))::varchar)::varchar);
END LOOP;
RETURN array_to_string(outstrarray,' ','');
END;
$$ LANGUAGE 'plpgsql';