Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PostgreSQL regex Problem

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
US
I'm using a dbi script on a database.
Someone entered some entries with extra info that I want to remove.

Found section on PostgreSQL's regex functions

I found that the following SQL works great, one by one on the entries.
Code:
SQL:
update products set product_description = regexp_replace((select product_description from products where product_description like 'Millstead%' AND product_id=19
), 'Millstead - ', '') where product_id=19;

my perl:
my $SQL = "update $updatetable set $fi3eld = regexp_replace((select $fi3eld from $updatetable where $fi3eld like \'\%$removeExp%\' AND $id_field = $id3), \'$removeExp\', '') where $id_field = $id3;";

With record abcdef,
Everything works fine for removing a complete string anywhere in record. cd->ok abc->ok def->ok, etc.

However, if I try to use ae as match, the entire string is removed. Same if I use ce as match.

I've reread the page a couple of times for this in PostgreSQL manual, but I don't understand what I need to do different.
 
Well, I figured out part of the answer.
Turns out that works a little more like perl than manual makes clear.
using .* seems to work, so I can clear out something in the middle ok, but that still leaves me with having to review for every record change, since some fields have values like:

Millstead Dimensional Lumber
or
Millstead 2 In. x 4In. x8 Ft. Pressure Treated Lumber
etc

One record has something in between Dimensional and Lumber that I want to keep.

So Mill.*umber can't be used except as pick and choose each time.

A lot of the stuff I want to remove is every to list, but varies in details.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top