Search Postgresql Archives

strpos NOT doing what I'd expect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux