CREATE TABLE my_table (
USER_IDX SERIAL NOT NULL
,PHONE_NUM VARCHAR(16) NOT NULL
,CHECK (TRANSLATE(phone_num, '0123456789', '') = '') -- 전화번호에 숫자만 허용
);
ALTER TABLE my_table ADD CONSTRAINT {constraint_name}
CHECK (TRANSLATE(phone_num, '0123456789', '') = '')
WITH cte AS (
SELECT ctid, TRANSLATE(phone_num, '-', '') as phone_num
FROM my_table
)
UPDATE my_table b
SET phone_num = a.phone_num
FROM cte a
WHERE a.ctid = b.ctid