Home > front end >  Take. a particular string from a TEXT in postgres
Take. a particular string from a TEXT in postgres

Time:05-20

I have one question: Below is an error message which is stored in a postgres table column, From this string i would like to extract only a part of the string, Is that possible to do in Postgres?

I would like to see odoo.exceptions.ValidationError: ('No MRP template was found for MO/10881!', None)' only this part.

In general all text starting with odoo.exceptions.ValidationError: until the end

How can i do it ? Any idea or suggestions?

'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)'

CodePudding user response:

You can use regexp_replace function to search for particular text then select the text following.

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. ...

In this case it seems you want the text after ValidationError:. Something like: (see demo)

select regexp_replace (message, '.*ValidationError:(.*)','\1') 
  from test; 
  • Related