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

validate a numeric column postgres

im trying to validate a column using postgresql
where values in the column are (0000-ASZAS) four numerical values-five alphbets

SELECT invoice_number,
CASE
WHEN invoice_number = '[0-9][0-9][0-9][0-9]-[A-Z][A-Z][A-Z][A-Z][A-Z]' 
THEN 'valid'
ELSE 'invalid'
END
from invoices;

also tried LIKE instead of =

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 :

You may use the ~ POSIX regex operator:

SELECT invoice_number,
       CASE WHEN invoice_number ~ '^[0-9]{4}-[A-Z]{5}$' 
            THEN 'valid'
            ELSE 'invalid' END
FROM invoices;
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