Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgres regexp_替换查询用法_Regex_Postgresql - Fatal编程技术网

Postgres regexp_替换查询用法

Postgres regexp_替换查询用法,regex,postgresql,Regex,Postgresql,我们有一个列,它有一个特定的前缀值,后跟动态数字,例如 AAAA0000 AAAA0001 AAAA0002 AAAA0003 ... ... 现在,我们希望在它存在的所有行中将前缀值从AAAA更新为bbbbbb。我尝试过使用regexp\u replace,replace以及其他可能的功能,但没有成功 你能帮我做这件事吗?我认为这里不需要正则表达式: update the_table set the_column = 'BBBB'||substr(the_column, 5) wher

我们有一个列,它有一个特定的前缀值,后跟动态数字,例如

AAAA0000
AAAA0001
AAAA0002
AAAA0003
... 
...
现在,我们希望在它存在的所有行中将前缀值从
AAAA
更新为
bbbbbb
。我尝试过使用
regexp\u replace
replace
以及其他可能的功能,但没有成功


你能帮我做这件事吗?

我认为这里不需要正则表达式:

update the_table
  set the_column = 'BBBB'||substr(the_column, 5)
where the_column like 'AAAA%';

以下是如何在此处使用
regexp\u replace

update the_table
   set the_column = regexp_replace(the_column, '^AAAA', 'BBBB');

更新表_name设置_列='BBBB'|| substr(_列,6,13),其中_列类似于'AAAA%'

其中as,6是数字的起始位置,13是字符串的结束位置。。
因此,值“BBBB”将更新到位置5,然后是上面提取的子字符串的串联。

那么您到底尝试了什么?问题是什么?还是错误?我尝试了以下选项,update tablename set column\u name=regexp\u replace('string\u value','…','update\u value'),其中ep2\u entity\u id='string\u value',但是,字符串值不能为常量,否则我无法更新其他记录。您的意思是第一个参数中的列名称,并且我需要更新字符串的前缀,因此regexp模式将不起作用。。我认为通过这种方式,只有tostring被覆盖,所有其他值都消失了(嗨,让我试试这个选项并在这里更新。我还没有尝试过这个选项。我尝试过下面的查询,只是做了一点即兴创作,它确实对我有用,更新table_name set the_column='bbbbbb'| | substr(ep2_entity_id,6,13)“AAAA%”之类的列;t非常感谢您的输入。