ronan
ronan

Reputation: 4672

Using replace in postgresql

I have the following SQL query using replace

SELECT 
            replace(
            replace(
            replace(
            replace(
            replace(email_text , 'This email is to notify you that for one or more records the Clearance has been Requested. Please follow the link below to go directly to this record.', '') 
              , ':', '</th>:<th>')  
              , '<BR/></th>','<BR/>') 
              , 'http</th>:<th>', 'http:') 
              , '</ul>', '</th></ul>') 
            INTO  v_result 
                FROM   record.notification  
                WHERE record_notification_id = p_recordnotification_id;

in above code I have

replace(email_text , 'This email is to notify you that for one or more records the Clearance has been Requested. Please follow the link below to go directly to this record.', '') 

Now instead I want to use like replace email_text with the sentence that starts with 'This email' and ends with 'this record.' instead of writing complete sentence . Please suggest.

Upvotes: 0

Views: 70

Answers (1)

Bohemian
Bohemian

Reputation: 425063

Use regex:

regex_replace(email_text, 'This email.*this record[.]', '')

Upvotes: 2

Related Questions