pgsql update select 查询并更新数据

with t as (select id,
                  birthday,
                  identification,
                  substring(identification, 7, 8),
                  concat_ws('-', substring(substring(identification, 7, 8), 1, 4),
                            substring(substring(identification, 7, 8), 5, 2),
                            substring(substring(identification, 7, 8), 7, 2)
                      ) as a
           from app_public.users
           where
               identification is not null
               and
               identification != ''
           )
UPDATE app_public.users t1
SET birthday = t.a
FROM t
WHERE t1.id = t.id;

-- select * -- from t;

你可能感兴趣的:(sql,数据库)