Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update column in postgreSQL first letter capital

How to update column in postgreSQL and set only first character capital?

Eg. TEST ---> Test

I tried, but not working

UPDATE car SET carName=UPPER(LEFT(carName,1)) + LOWER(SUBSTRING(carName,2,LEN(carName)))
like image 519
Pointer Avatar asked Oct 20 '25 03:10

Pointer


1 Answers

It should not be a problem:

postgres=# select * from f10;
+--------+
|   a    |
+--------+
| nazdar |
+--------+
(1 row)

postgres=# update f10 set a = upper(substring(a from 1 for 1)) || lower(substring(a from 2));
UPDATE 1
postgres=# select * from f10;
+--------+
|   a    |
+--------+
| Nazdar |
+--------+
(1 row)

Maybe you can use initcap functions too:

postgres=# select initcap('hello world');
+-------------+
|   initcap   |
+-------------+
| Hello World |
+-------------+
(1 row)
like image 120
Pavel Stehule Avatar answered Oct 21 '25 16:10

Pavel Stehule



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!