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.
Check the ASCII value of each character for the following conditions: If the ASCII value lies in the range of [65, 90], then it is an uppercase letter. If the ASCII value lies in the range of [97, 122], then it is a lowercase letter. If the ASCII value lies in the range of [48, 57], then it is a number.
Use the INITCAP() function to convert a string to a new string that capitalizes the first letter of every word. All other letters will be lowercase.
To check if a letter in a string is uppercase or lowercase use the toUpperCase() method to convert the letter to uppercase and compare it to itself. If the comparison returns true , then the letter is uppercase, otherwise it's lowercase.
PostgreSQL names are case sensitive. By default, AWS Schema Conversion Tool (AWS SCT) uses object name in lowercase for PostgreSQL. In most cases, you'll want to use AWS Database Migration Service transformations to change schema, table, and column names to lower case.
You can use Postgres regexp to test for your specific condition:
select * from sample
where col ~ E'^[[:upper:]][^[:upper:]]'
You could use E'^[[:upper:]][[:lower:]]'
if the second character must be lowercase alpha instead of any non-uppercase.
If you want to know whether a string contains at least one lower case character then you can use the upper function [upper(mystr)=mystr]:
dbname=> select upper('AAbbCC')='AAbbCC';
?column?
----------
f
(1 row)
dbname=> select upper('AABBCC')='AABBCC';
?column?
----------
t
(1 row)
You can use the same logic for checking that a string contains at least one upper case character with the lower() sql function.
For more complicated pattern, you will need to use regular expression or substring as proposed by earlier answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With