simple text parsing function

From: "Kevin Duffy" <KD(at)wrinvestments(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: simple text parsing function
Date: 2008-11-21 20:35:44
Message-ID: DFC309C8A42633419600522FA8C4AE1A561118@mail-01.wrcapital.corp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Zagato 2008-11-22 01:34:23 Interval Format
Previous Message Oliveiros Cristina 2008-11-21 16:53:46 Re: function - string ends with