Search code examples
sqlpostgresqlsql-update

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)))

Solution

  • 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)