【发布时间】:2011-05-16 21:00:45
【问题描述】:
我想在 postgres 中运行一个查询,查找文件路径为 cor/* 的表中的所有行并将它们设置为 con/*。
在伪代码中:
UPDATE photo set filepath="con/*" where filepath="cor/*";
请任何人帮助我正确的 postgres 语法?这在 postgres 中可行吗?
非常感谢!
【问题讨论】:
标签: postgresql
我想在 postgres 中运行一个查询,查找文件路径为 cor/* 的表中的所有行并将它们设置为 con/*。
在伪代码中:
UPDATE photo set filepath="con/*" where filepath="cor/*";
请任何人帮助我正确的 postgres 语法?这在 postgres 中可行吗?
非常感谢!
【问题讨论】:
标签: postgresql
其实并不需要正则表达式:
UPDATE photo
SET filepath = 'con' || substring(filepath, 4)
WHERE filepath LIKE 'cor/%'
【讨论】:
有一个 regexp_replace() 函数:
http://www.postgresql.org/docs/current/static/functions-string.html
update photo
set filepath = regexp_replace(filepath, '^cor/', 'con/')
where filepath ~ '^cor/';
【讨论】: