1

I have a column named foo and I want to replace certain values from the cells in this column. foo is a string column. The values are

1, 01, 2, 02, 3, 4, 010, 12, ...

I tried

replace("foo",'1','01')

But this replaces me all the ones 1 with 01, resulting in

01, 0101, 2, 02, 3, 4, 01010, 012, ...

I only want completly matching numbers, hence

01, 01, 2, 02, 3, 4, 010, 12, ...

How to do that?

1
  • How about something like: CASE WHEN "foo" LIKE '1' THEN '01' ELSE "foo" END
    – Ben W
    Commented Aug 19, 2022 at 10:00

2 Answers 2

1

You can use function lpad(): lpad( "foo", 2,'0')

From documentation:

lpad() returns a string padded on the left to the specified width, using a fill character.

0

I did it with

case 
when "foo" is '1' then '01' 
else "foo" end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.