我有一個名為“master”的表,例如:
| 物品 | 成本 |
|---|---|
| 蘋果 | 4.47 |
| 車 | 7,232.64 |
| 自行車 | 499.99 |
目前 item 和 cost 都是 TEXT 資料型別。我想將成本轉換為 NUMERIC,但由于汽車價格中的逗號而出現錯誤。
如何從成本列中洗掉所有逗號?
dbname=# ALTER TABLE master ALTER COLUMN cost TYPE numeric USING cost::numeric;
錯誤:數字型別的輸入語法無效:“7,232.64”
uj5u.com熱心網友回復:
使用regexp_replace:
UPDATE master SET cost = regexp_replace(cost, ',', '', 'g');
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/481687.html
標籤:sql 正则表达式 细绳 PostgreSQL 代替
