simple text parsing function

Поиск
Список
Период
Сортировка
Искать

simple text parsing function

От:
"Kevin Duffy" <KD@wrinvestments.com>
Дата:

Hello All:

 

I am requesting your kind assistance with a simple text parsing function.

The source code for the function is below. What is interesting is that the

path through the code that actually does something works.  The simple

path through the code fails.

 

For example

select getrfs_bbcode('CHF/USD 12/17/2008 CURNCY     ', null, null);  returns  "CHFUSD  CURNCY     "  this is correct.

 

select getrfs_bbcode('BPZ8 CURNCY              ',  NULL, NULL);   returns nothing.  I need to receive 'BPZ8 CURNCY              '  in this case.

 

 

What am I missing? 

 

Many thanks for your assistance.

 

KD

 

 

CREATE OR REPLACE FUNCTION getrfs_bbcode( bbcode_in bpchar, sectype_bbsuffix_in bpchar, sectypekey_in integer )

  RETURNS character AS

$BODY$

 

DECLARE

  rtn_bbcode char(25);

  tmp_bbcode  char(25);

  abbcode char(10)[3];

BEGIN

 

  tmp_bbcode  := upper( rtrim(bbcode_in ) );

  -- 

  if tmp_bbcode like '%CURNCY'  then

     if strpos( tmp_bbcode, '/' )  > 0  then

        --  Is there / in the BB Code

        abbcode :=  string_to_array(tmp_bbcode, ' ');

        rtn_bbcode := replace(abbcode[1], '/', '')  ||'  '|| abbcode[3];

     else

        rtn_bbcode := tmp_bbcode;      -- simple pass though case does not work?!?!

 

     end if;    

    

  end if; 

 

 return  rtn_bbcode ;

 

END

$BODY$

 

LANGUAGE 'plpgsql' VOLATILE;

 

Kevin Duffy

 

Re: simple text parsing function

От:
John DeSoi <desoi@pgedit.com>
Дата:

On Nov 21, 2008, at 3:35 PM, Kevin Duffy wrote:

> select getrfs_bbcode('BPZ8 CURNCY              ',  NULL, NULL);    
> returns nothing.  I need to receive 'BPZ8 CURNCY              '  in  
> this case.
>
>
> What am I missing?


I think it is because of your choice of types:

select rtrim('BPZ8 CURNCY  ') like '%CURNCY'; --> true

select rtrim('BPZ8 CURNCY  ')::char(25) like '%CURNCY'; --> false

Interestingly, it works if you make your comparison using ~ '.*CURNCY'



John DeSoi, Ph.D.





FAQ