How to replace the first letter of a string using SQL and Postgres?

Viewed 267

I have a database column of varchar(191) with strings in the database. We need to replace the first letter of every string with an "E". So for instance, we have:

  • Cuohvi-AQNqalPq8zdr1cOA

Needs to be changed to

  • Euohvi-AQNqalPq8zdr1cOA

Do you know how we can achieve this in Postgres with a SQL query? It needs to be updated for the whole table.

2 Answers

Per docs use overlay():

UPDATE the_table SET the_field = overlay(the_field placing 'E' from 1 for 1);

Related