Thread: Capitalizing First Letter of Every Word
Hi *,
I have a database of products, and the client entered everything in all caps. While there is no intelligent way to do change everything to what it should be, changing the first letter of every word to uppercase and everything else to lowercase would at least look better (except for the occasional acroynym).
Is there a function to do that? I think I can handle everything except breaking the whole column up into individual words... I know how I would do it in PHP (and I may have to resort to that), but would prefer to do it in the db.
Any suggestions?
Thanks,
Brian
My mistake, there _is_ a function already: initcap(text) text Converts first letter of each word (whitespace separated) to upper case. initcap('hello thomas') Hello Thomas -Knight On Tue, 26 Jun 2001, Alex Knight wrote: > Brian, > > My suggestion would be to create a query that gets all the values for that > table and does something like the following: > > select upper(substring('knight' from 1 for 1)) || > lower(substring('knight') from 2)); > > The problem with this, is it doesn't do anything except the first > character. > > You could probably write something a bit more complex in a procedure or > function. > > -Knight > > On Tue, 26 Jun 2001, Brian T. Allen wrote: > > > Hi *, > > > > I have a database of products, and the client entered everything in all caps. While there is no intelligent way to dochange everything to what it should be, changing the first letter of every word to uppercase and everything else to lowercasewould at least look better (except for the occasional acroynym). > > > > Is there a function to do that? I think I can handle everything except breaking the whole column up into individual words... I know how I would do it in PHP (and I may have to resort to that), but would prefer to do it in the db. > > > > Any suggestions? > > > > Thanks, > > Brian > > > >
Brian, My suggestion would be to create a query that gets all the values for that table and does something like the following: select upper(substring('knight' from 1 for 1)) || lower(substring('knight') from 2)); The problem with this, is it doesn't do anything except the first character. You could probably write something a bit more complex in a procedure or function. -Knight On Tue, 26 Jun 2001, Brian T. Allen wrote: > Hi *, > > I have a database of products, and the client entered everything in all caps. While there is no intelligent way to dochange everything to what it should be, changing the first letter of every word to uppercase and everything else to lowercasewould at least look better (except for the occasional acroynym). > > Is there a function to do that? I think I can handle everything except breaking the whole column up into individual words... I know how I would do it in PHP (and I may have to resort to that), but would prefer to do it in the db. > > Any suggestions? > > Thanks, > Brian >
On Tue, 26 Jun 2001, Brian T. Allen wrote: > Hi *, > > I have a database of products, and the client entered everything in all caps. While there is no intelligent way to dochange everything to what it should be, changing the first letter of every word to uppercase and everything else to lowercasewould at least look better (except for the occasional acroynym). > > Is there a function to do that? I think I can handle everything except breaking the whole column up into individual words... I know how I would do it in PHP (and I may have to resort to that), but would prefer to do it in the db. > > Any suggestions? try this: UPDATE lala_table SET lala_col=initcap(lower(lala_col)); It will make the first letter of every word uppercase (close enough) If not satisfied, you can do it by extracting the first character, capitalizing, and then lower()ing the rest of the message.Check http://www.postgresql.org/idocs/index.php?functions-string.html for char_length(),substring(),upper(),lower() cheers, thalis > > Thanks, > Brian >
select initcap(product_name) from products
initcap() is available in 7.1, maybe earlier versions too.
--rob
----- Original Message -----From: Brian T. AllenSent: Tuesday, June 26, 2001 6:56 PMSubject: Capitalizing First Letter of Every WordHi *,I have a database of products, and the client entered everything in all caps. While there is no intelligent way to do change everything to what it should be, changing the first letter of every word to uppercase and everything else to lowercase would at least look better (except for the occasional acroynym).Is there a function to do that? I think I can handle everything except breaking the whole column up into individual words... I know how I would do it in PHP (and I may have to resort to that), but would prefer to do it in the db.Any suggestions?Thanks,Brian