Update column in postgreSQL first letter capital

How update column in postgreSQL set only first character capital?

Eg. TEST ---> Test

I'm try, but not working

UPDATE car SET carName=UPPER(LEFT(carName,1)) + LOWER(SUBSTRING(carName,2,LEN(carName)))

1 answer

  • answered 2018-07-12 07:37 Pavel Stehule

    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)