Today’s post is a one-liner that saves me a few lines of PHP every time I do a people query.

I used to always select my clients’ or customers’ names from the database, then use PHP/Ruby/something to grab just the first word of the name.

From now on I’m doing it in the database directly, though it took a while to figure out how.

SELECT name, INITCAP(SPLIT_PART(name, ‘ ‘, 1)) AS firstname FROM clients

(Ok so it only took like 3 minutes to figure out but I’m posting it here so I don’t lose it.)

:-)