I have a table which looks like this:
| id | price | barcode |
|---|---|---|
| 1 | 300 | A_100-15437859603-233 |
| 2 | 200 | A_123-49875452222-128 |
| 3 | 180 | A_231-21284568323-367 |
| 4 | 150 | B_122457 |
Having two (or more) formats of data in the "barcode" column. Now my queries look like this:
SELECT * FROM my_table
WHERE barcode like 'A_%' AND
SUBSTRING(barcode, '-(.*?)-')='15437859603'
In order to find the first row for example. This table has tens of millions of rows, how can I speed up this regex search in PostgreSQL? Can I create an index on SUBSTRING(barcode, '-(.*?)-')?
LIKE()operator. For example something likelike 'A[_]%[-]15437859603[-]%'?