0

i'm trying to return a column with every instance of a number replaced by '!'.

the following code only replaces the first instance from each row:

select project, commits, contributors, regexp_replace(address, '[0-9]', '!') as address
from repositories

1BcJBCAYqW9 should return as so !BcJBCAYqW! but the output I get is !BcJBCAYqW9, where the second digit does not change.

0

1 Answer 1

1

The code works as expected in MySQL and Oracle. So, I am going to guess you are using Postgres or a Postgres-derived database.

Postgres requires an additional argument to specify that all occurrences should be replaced:

select regexp_replace(address, '[0-9]', '!', 'g') as address
from (select '1BcJBCAYqW9' as address ) x
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.