Skip to content
Advertisement

deleting all occurrences of a character before the next different character

In a postgres table I have a column with values like:

code
=============
000A450
00BVDDE
0FGR0SE
GVSDD33

I need to delete all 0 before the next character that is NOT a 0. So, the previous column will became:

new Code
=============
A450
BVDDE
FGR0SE
GVSDD33

Is this possible in psql?

Advertisement

Answer

SELECT ltrim('00BVDDE', '0');

 ltrim 
═══════
 BVDDE
(1 row)

(No comment necessary.)

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement