拿。 postgres 中 TEXT 中的特定字符串
Take. a particular string from a TEXT in postgres
我有一个问题:
下面是存储在 postgres table 列中的一条错误消息,从这个字符串中我只想提取字符串的一部分,在 Postgres 中可以这样做吗?
我想看odoo.exceptions.ValidationError: ('No MRP template was found for MO/10881!', None)' 只有这一部分。
通常所有以 odoo.exceptions.ValidationError 开头的文本:直到结尾
我该怎么做?有什么想法或建议吗?
'Traceback (most recent call last):
File "/opt/src/addons_OCA/queue/queue_job/controllers/main.py", line 101, in runjob
self._try_perform_job(env, job)
File "/opt/src/addons_OCA/queue/queue_job/controllers/main.py", line 61, in _try_perform_job
job.perform()
File "/opt/src/addons_OCA/queue/queue_job/job.py", line 466, in perform
self.result = self.func(*tuple(self.args), **self.kwargs)
File "/opt/src/addons/costs/models/mrp_production.py", line 163, in trigger_calculate_all_costs
self.calculate_all_costs()
File "/opt/src/addons/sucosts/models/costline_mixin.py", line 284, in calculate_all_costs
rec.generate_service_products()
File "/opt/src/addons/mrp_product_templates/models/mrp_production.py", line 660, in generate_service_products
MO=self.name)))
odoo.exceptions.ValidationError: ('No MRP template was found for MO/10881!', None)'
您可以使用 regexp_replace 函数搜索特定文本,然后 select 后面的文本。
The regexp_replace function provides substitution of new text for
substrings that match POSIX regular expression patterns. It has the
syntax regexp_replace(source, pattern, replacement [, flags ]). The
source string is returned unchanged if there is no match to the
pattern. ...
在这种情况下,您似乎需要 ValidationError: 之后的文本。类似于:(参见 demo)
select regexp_replace (message, '.*ValidationError:(.*)','')
from test;
我有一个问题: 下面是存储在 postgres table 列中的一条错误消息,从这个字符串中我只想提取字符串的一部分,在 Postgres 中可以这样做吗?
我想看odoo.exceptions.ValidationError: ('No MRP template was found for MO/10881!', None)' 只有这一部分。
通常所有以 odoo.exceptions.ValidationError 开头的文本:直到结尾
我该怎么做?有什么想法或建议吗?
'Traceback (most recent call last):
File "/opt/src/addons_OCA/queue/queue_job/controllers/main.py", line 101, in runjob
self._try_perform_job(env, job)
File "/opt/src/addons_OCA/queue/queue_job/controllers/main.py", line 61, in _try_perform_job
job.perform()
File "/opt/src/addons_OCA/queue/queue_job/job.py", line 466, in perform
self.result = self.func(*tuple(self.args), **self.kwargs)
File "/opt/src/addons/costs/models/mrp_production.py", line 163, in trigger_calculate_all_costs
self.calculate_all_costs()
File "/opt/src/addons/sucosts/models/costline_mixin.py", line 284, in calculate_all_costs
rec.generate_service_products()
File "/opt/src/addons/mrp_product_templates/models/mrp_production.py", line 660, in generate_service_products
MO=self.name)))
odoo.exceptions.ValidationError: ('No MRP template was found for MO/10881!', None)'
您可以使用 regexp_replace 函数搜索特定文本,然后 select 后面的文本。
The regexp_replace function provides substitution of new text for substrings that match POSIX regular expression patterns. It has the syntax regexp_replace(source, pattern, replacement [, flags ]). The source string is returned unchanged if there is no match to the pattern. ...
在这种情况下,您似乎需要 ValidationError: 之后的文本。类似于:(参见 demo)
select regexp_replace (message, '.*ValidationError:(.*)','')
from test;