【发布时间】:2022-07-06 16:01:48
【问题描述】:
我想编写一个 SQL 迁移来将“name”列拆分为“users”表中的“first_name”和“last_name”列,我已经创建了 2 列。
我正在寻找一个看起来像的命令
UPDATE users
SET (first_name, last_name)
VALUES ({expression for first name}, {expression for last name});
我接受两个部分之间的边界是第一个空白字符的假设。 (即对于 John Doe Jr,姓氏应该是 'Doe Jr')
我尝试使用regexp_match(name, [^\s]*) 作为名字,但对于name="John Doe" 它返回first_name="{John}",我该如何解决这个问题,或者有比使用regexp_match 更好的方法吗?
【问题讨论】:
-
另外,注意像 Doe, John - John Doe Jr - Mr John E Doe - Doe, Mr John E Esq 这样的事情。 - 等等。
标签: sql regex postgresql database-migration