Forum OpenACS Development: Re: String manipulation in Postgres

Collapse
Posted by russ m on
in TCL you can anchor the match pattern to the start of the string (also, regsub only operates on the first match unless you pass the -all flag)
regsub {^csr_contact_} $string {} id

in SQL it's not quite so clean... if you know there'll only be one instance of "csr_contact_" in the string you can use

replace(name,'csr_contact_','')
but in the general case it looks like you'd need to do something like
select CASE WHEN name like 'csr_contact_%' THEN substring(name from 13) ELSE name END
ugghhh...