--Apple-Mail-164-417391145
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
CODE:
===============================
CREATE OR REPLACE FUNCTION find_next_delim(invar varchar, delimlist
varchar) RETURNS integer AS
$$
/* OVERLOADED Function. The other version takes a 3rd parameter as
the
starting position in invar.
*/
DECLARE
achar character := '' ;
j int := 0 ;
BEGIN
IF length(delimlist) = 0 THEN
RAISE NOTICE 'In function \'find_next_delim\' the delimiter
cannot be null.' ;
END IF ;
FOR i IN 1 .. length(invar)
LOOP
j := j + 1 ;
achar := substring(invar from i for 1 ) ;
RAISE NOTICE 'achar is R%S',achar ;
IF strpos(delimlist,achar) <> 0 THEN
RETURN j ;
END IF ;
END LOOP ;
RETURN 0 ;
END ;
$$ LANGUAGE plpgsql ; /* find_next_delim */
WHAT'S HAPPENING:
===============================
airburst=# select find_next_delim('ralph smith','3') ;
NOTICE: achar is RrS
NOTICE: achar is RaS
NOTICE: achar is RlS
NOTICE: achar is RpS
NOTICE: achar is RhS
NOTICE: achar is R S
find_next_delim
-----------------
6
(1 row)
airburst=# select find_next_delim('ralph smith','') ; -- for the heck
of it, that's a null
NOTICE: In function 'find_next_delim' the delimiter cannot be null.
NOTICE: achar is RrS
NOTICE: achar is RaS
NOTICE: achar is RlS
NOTICE: achar is RpS
NOTICE: achar is RhS
NOTICE: achar is R S
find_next_delim
-----------------
6
(1 row)
WHY find a match on the space???
Thanks!
--Apple-Mail-164-417391145
Content-Type: text/html;
charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
<html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
-webkit-line-break: after-white-space; =
">CODE:<div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</div><div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;">CREATE OR REPLACE =
FUNCTION find_next_delim(invar varchar, delimlist varchar) RETURNS =
integer AS</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;">$$</span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: =
12px;"><br></span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;">/* OVERLOADED Function. The =
other version takes a 3rd parameter as the</span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;"> =
starting position in =
invar.</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;">*/</span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: =
12px;"><br></span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;">DECLARE</span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: =
12px;"> </span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;"> achar =
character :=3D '' ;</span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;"> j =
int :=3D 0 =
;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> </span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: =
12px;">BEGIN</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"><br></span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;"> IF =
length(delimlist) =3D 0 THEN</span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;"> =
RAISE NOTICE 'In function \'find_next_delim\' the delimiter cannot =
be null.' ;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> END IF =
;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"><br></span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: =
12px;"> </span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;"> FOR i =
IN 1 .. length(invar) </span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: =
12px;"> LOOP</span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: =
12px;"><br></span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> j :=3D j + 1 =
;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> achar :=3D substring(invar =
from i for 1 ) ;</span></font></div><div><font class=3D"Apple-style-span"
=
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> RAISE NOTICE 'achar is =
R%S',achar ;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> IF strpos(delimlist,achar) =
<> 0 THEN</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> RETURN j =
;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> END IF =
;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> =
</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> END LOOP =
;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> </span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;"> RETURN =
0 ;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;"> </span></font></div><div><font =
class=3D"Apple-style-span" face=3D"Courier" size=3D"3"><span =
class=3D"Apple-style-span" style=3D"font-size: 12px;">END =
;</span></font></div><div><font class=3D"Apple-style-span" =
face=3D"Courier" size=3D"3"><span class=3D"Apple-style-span" =
style=3D"font-size: 12px;">$$ LANGUAGE plpgsql ; /* =
find_next_delim =
*/</span></font></div></div><div><br></div><div><br></div><div><br></div><=
div><br></div><div>WHAT'S =
HAPPENING:</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</div><div>airburst=3D# select =
find_next_delim('ralph smith','3') =
;</div><div><div><br></div><div>NOTICE: achar is =
RrS</div><div>NOTICE: achar is RaS</div><div>NOTICE: achar =
is RlS</div><div>NOTICE: achar is RpS</div><div>NOTICE: =
achar is RhS</div><div>NOTICE: achar is R =
S</div><div> find_next_delim </div><div>-----------------</div><=
div> =
6</div><div>(1 =
row)</div><div><br></div><div><br></div><div><div>airburst=3D# select =
find_next_delim('ralph smith','') ; -- for the heck of it, that's =
a null</div><div><br></div><div>NOTICE: In function =
'find_next_delim' the delimiter cannot be null.</div><div>NOTICE: =
achar is RrS</div><div>NOTICE: achar is =
RaS</div><div>NOTICE: achar is RlS</div><div>NOTICE: achar =
is RpS</div><div>NOTICE: achar is RhS</div><div>NOTICE: =
achar is R =
S</div><div> find_next_delim </div><div>-----------------</div><=
div> =
6</div><div>(1 row)</div><div><br></div><div>WHY find a match on the =
space???</div><div><br></div><div>Thanks!</div><div><br></div></div></div>=
</body></html>=
--Apple-Mail-164-417391145--


|