simple text parsing function - Mailing list pgsql-sql

From Kevin Duffy
Subject simple text parsing function
Date
Msg-id DFC309C8A42633419600522FA8C4AE1A561118@mail-01.wrcapital.corp
Whole thread Raw
Responses Re: simple text parsing function
List pgsql-sql

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

 

pgsql-sql by date:

Previous
From: "Oliveiros Cristina"
Date:
Subject: Re: function - string ends with
Next
From: Zagato
Date:
Subject: Interval Format