postgresql 拼错的数据

rks48beu  于 2022-12-12  发布在  PostgreSQL
关注(0)|答案(2)|浏览(113)

How to correct below misspelled data in column market:
| market |
| ------------ |
| SocialMediaAdvertising |
| SocialInvesting |
| FinancialExchanges |
| CloudMagement |
| VentureCapital |
I don't know what syntax to write. But output should be as below:
| market |
| ------------ |
| Social Media Advertising |
| Social Investing |
| Financial Exchanges |
| Cloud Magement |
| Venture Capital |

kx1ctssn

kx1ctssn1#

Use can use the regexp_replace() function to insert each a space before each upper case letter. (See demo )

update markets  
   set market = ltrim(regexp_replace(market, '([A-Z])', ' \1', 'g'));

Caution: As presented this Updates every occurrence of an upper case letter inserting a space before it. The ltrim removes the space inserted at the beginning of the column. Any uppercase letter preceded by a space creates a double space. Make sure you validate result.

9jyewag0

9jyewag02#

You can run a series of SQL updates since there aren't many changes. For example

UPDATE your_table set market="Social Media Advertising" where market="SocialMediaAdvertising";
UPDATE your_table set market="Social Investing" where market="SocialInvesting";
UPDATE your_table set market="Financial Exchanges" where market="FinancialExchanges";
UPDATE your_table set market="Cloud Magement" where market="CloudMagement";
UPDATE your_table set market="Venture Capital" where market="VentureCapital";

Cautions: Be sure to replace your_table with the actual name of the table you want to update, for each SQL statement.

You might have a typo with "Magement", but I'm not sure

相关问题