How to determine if a character is uppercase or lowercase in postgresql?

Pupkov-Zadnij picture Pupkov-Zadnij · Dec 4, 2012 · Viewed 20.1k times · Source

I have failed to find any function like isupper or islower in postgresql. What I actually need is to select all the records from a table, where one of the columns contains capitized (but not uppercase) words. That is, the first symbol of each word is uppercase, and the second is lowercase. Words can be written in any language.

Answer

BobG picture BobG · Dec 4, 2012

What about just selecting the rows where the case of the first letter in the column is not equal to the lowercase version of the first letter in the column?

Something like:

SELECT * FROM table 
    WHERE SUBSTRING(col FROM 1 FOR 1) != LOWER(SUBSTRING(col FROM 1 FOR 1))

In theory, the above should take the database charset/locale into account as well.