need help of regular expression genius

GHUM haraldarminmassa at gmail.com
Wed Aug 2 11:27:01 EDT 2006


I need to split a text at every ; (Semikolon), but not at semikolons
which are "escaped" within a pair of $$ or $_$ signs.

My guess was that something along this should happen withing csv.py;
but ... it is done within _csv.c :(

Example: the SQL text should be splitted at "<split here>" (of course,
those "split heres" are not there yet :)

set interval 2;
<split here>
CREATE FUNCTION uoibcachebetrkd(bigint, text, text, text, text, text,
timestamp without time zone, text, text) RETURNS integer
    AS $_$
        DECLARE
            result int4;
        BEGIN
            update bcachebetrkd set
                name=$2, wieoftjds=$3, letztejds=$4, njds=$5,
konzern=$6, letztespeicherung=$7, betreuera=$8, jdsueberkonzern=$9
            where id_p=$1;
        IF FOUND THEN
            result:=-1;
        else
           insert into bcachebetrkd (
           id_p, name, wieoftjds, letztejds, njds, konzern,
letztespeicherung, betreuera, jdsueberkonzern
           )
            values ($1, $2, $3, $4, $5, $6, $7, $8, $9);
            result:=$1;
        END IF;
            RETURN result;
        END;
        $_$
    LANGUAGE plpgsql;
<split here>
CREATE FUNCTION set_quarant(mylvlquarant integer) RETURNS integer
    AS $$
    BEGIN
	perform relname from pg_class
            where relname = 'quara_tmp'
              and case when has_schema_privilege(relnamespace, 'USAGE')
                    then pg_table_is_visible(oid) else false end;
        if not found then
            create temporary table quara_tmp (
                lvlquara integer
            );
	else
	   delete from quara_tmp;
	end if;

	insert into quara_tmp values (mylvlquarant);
  return 0;
  END;
 $$
    LANGUAGE plpgsql;
<split here>

Can anybody hint me in the right direction, how a RE looks for "all ;
but not those ; within $$" ?

Harald




More information about the Python-list mailing list