Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Postgres find string starting with specific characters

I have this table, in which the order_name was randomly typed. I want to extract the order code after 437. for 22 characters in their original format, e.g. 437.8/03-87 22LA190028 (it was wrongly written in the second record).

id order_name
1 First order 437.8/03-87 22LA190028
2 Second order 437.8-03-87 22LA190028
3 First order 437.3/10-87 16NY100013 – Return
4 Order 21.02.2022 437.8/10-87 16WA239766
5 437.8/10-87 16NY100234 – Paid
6 First order (437.8/03-87 22LA190028)
7 Visit 02.02.2023 Order 437.5/10-87 16DC107765

I will really appreciate your help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If the string you want ALWAYS starts with 437 and has a length of 22 you can use the following regex statement:

437...................

I think you can select the result of this in postgres by:

SELECT REGEXP_MATCHES(order_name,#'437...................')
FROM yourtable
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading