0

I have a table and I have added a new column to it. I need to populate this new column and also set the default value for it.

The value of the new col is obtained by concatenating two strings based on the values of other columns: the first string is the sum COL_1 + 10000 the second string is a obtained by stripping everything but the alphanumerics in COL_2

Update TABLE set NEW_COL = CONCAT ((SUM (10000 + COL_1)), (preg_replace('/[\s\W]+/','',COL_2)))

This will be the default value for the column

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
florina
  • 13
  • 5

1 Answers1

0

The reason your update is failing is that preg_replace() is not a valid MySQL function. That's a PHP function. Here's a relevant question that addresses that functionality in MySQL:

How to do a regular expression replace in MySQL?

Community
  • 1
  • 1
Ike Walker
  • 64,401
  • 14
  • 110
  • 109