Search code examples
sqlpostgresqlsubstring

How can I cut the 1st letter from a cell and add to another cell in PSQL?


I have a long list, and I want to add the first letter into another cell with psql command.

A header Another header
John J
Lila L
Dwane D
Zaba Z
Kiol K
Longi L
Uthe U
Hell H

Like this.


Solution

  • You can use the left() postgres function to extract the first charater from a string, see the manual. Try something like this :

    SELECT "A header", left("A header", 1) AS "Another header"
      FROM your_table