0

I want to replace the first word before delimeter ' ,' with ' 0, the first word ')

select replace('tab,graph,map', split_part('tab,graph', ',', 1) like 'tab','0, tab')

ERROR: function replace(unknown, boolean, unknown) does not exist LINE 1: select replace('tab,graph,map', split_part('tab,graph', ',',... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

2 Answers 2

2

The replace function replaces all occurrences of the string so you have to make sure the string to replace is unique or use something else. However, regexp_replace only replaces the first occurrence by default so you can use that; your question is a little unclear about what the expected output is but maybe this is is what you're looking for:

=> select regexp_replace('tab,graph,map', ',', '0,');
 regexp_replace 
----------------
 tab0,graph,map

Or this one:

=> select regexp_replace('tab,graph,map', 'tab,', '0,');
 regexp_replace 
----------------
 0,graph,map

Or maybe even this:

=> select regexp_replace('tab,graph,map', 'tab,', '0,,');
 regexp_replace 
----------------
 0,,graph,map
Sign up to request clarification or add additional context in comments.

Comments

-1

you need to cast, since the function expects replace(text, text, text) and does not know how to handle your literal strings calling them unknown...

cast('tab,graph,map' AS text)

also the 2nd param is a LIKE comparison ? which returns boolean, but the function replace expects it to be the delimiter.

CAST(split_part('tab,graph', ',', 1) AS text)

finally the last param (same problem as the first)

cast('0, tab' AS text)

of course if you really just want to prepend '0, ' to your string, 'tab,graph,map' you could just do that...

SELECT '0, ' || 'tab,graph,map' ;

1 Comment

that is not only to prepend '0, ' but the word tab is not only in the first word ex : tab,map,tab.graph... i want to replace tab in the first word before delimeter with '0,'

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.