Re: Postgres 8.4 literal escaping
От | Andreas |
---|---|
Тема | Re: Postgres 8.4 literal escaping |
Дата | |
Msg-id | 4A5B4A86.3050306@gmx.net обсуждение исходный текст |
Ответ на | Re: Postgres 8.4 literal escaping (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: Postgres 8.4 literal escaping
|
Список | pgsql-general |
Hi, I've got a similar issue with a function that uses regular-expression-magic. I got it from the sql list and it works but I'm just about 75% aware of how. Still PG complains about those \\ everywhere. Replacing every \ by || E'\\' || would make it ... cough ... not looking cuter as it allready is. What would be the correct syntax here? I need it to search phone numbers. The function strips all characters that are no number or "+" out of the input-string. If the international part is "+49" or "0049" it get reduced to 0. CREATE OR REPLACE FUNCTION cleanphonenr(text) RETURNS text AS $BODY$ BEGIN RETURN CASE WHEN regexp_replace($1, E'[^0-9+]', '', 'g') ~ E'^(\\+|00)49' THEN '0'|| regexp_replace( regexp_replace( regexp_replace($1, E'[^0-9+()]', '', 'g') , '\\(0\\)||\\(||\\)', '', 'g') , E'^(?:\\+|00)49(.*)', E'\\1') WHEN regexp_replace($1, E'[^0-9+]', '', 'g') ~ E'^(\\+|00)' THEN '+'|| regexp_replace( regexp_replace( regexp_replace($1, E'[^0-9+()]', '', 'g') , '\\(0\\)||\\(||\\)', '', 'g') , E'^(?:\\+||00)(.*)', E'\\1') ELSE regexp_replace($1, E'[^0-9]', '', 'g') END; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE COST 100;
В списке pgsql-general по дате отправления: