How to do Case a Case Insensitive Replace in PostgreSQL (I'll show you at the end!) | Essential SQL

Опубликовано: 23 Октябрь 2024
на канале: Essential SQL (EssentialSQL)
1,263
19

You want to replace all occurrences of a substring with a new substring using PostgreSQL, MySQL, or SQL Server.

More importantly watch until the end if you want to know how do a case insensitive replacement in PostgreSQL.

One Last Thing...
This video is part of my Beginner Learning series. If you're interested in learning SQL subscribe to @Essential SQL and then check out our Intermediate Learner Playlist. Of course, I also encourage you to visit https://www.essentialsql.com to learn even more!

Important links:
Sample PizzaDB: https://github.com/kwenzel1/Essential...
Corresponding Article: https://www.essentialsql.com/replace-...

Source Code:
select * from Product


REPLACE(productname, 'Coke', 'Pepsi')


SELECT productname OriginalProductList,
REPLACE(productname, 'Coke', 'Pepsi') NewProductList
FROM Product


UPDATE Product
SET productname = REPLACE(productname, 'Coke', 'Pepsi')



REGEXP_REPLACE(productname, 'coke', 'Pepsi','i')