views:

24

answers:

1

The purpose of the function is to take a string and, if it contains parens, delete everything in the parens. Here's what I have:

CREATE FUNCTION clearmethodparams(IN qname text) RETURNS text AS
  $BODY$        
  IF position($o$($o$ in qname) = 0 THEN
    return qname;
  ELSE 
    return substring(qname from 0 for position($p$($p$ in qname)) || $c$)$c$;
  END IF;
  $BODY$
LANGUAGE sql VOLATILE;

The error it keeps giving me is

ERROR: syntax error at or near "IF" LINE 3: IF position($o$($o$ in qname) = 0 THEN

I've been trying to find some good documentation on function syntax, but nothing so far has been helpful.

+1  A: 

You need to "convert" the function from an SQL function to a PL/pgSQL one - replace "LANGUAGE sql" with "LANGUAGE plpgsql" in your CREATE FUNCTION statement. Also you will need to "wrap" your code in a proper block.

OTOH you could probably achieve the same with an SQL function, e.g. with some clever user of CASE or similar.

Milen A. Radev
Thanks, Milen, but it's still giving the same error after your edit... WAIT I got it - I just needed BEGIN and END statements too. THANKS!!!
Kyle P
Oh, yes - I'll add that bit for future reference.
Milen A. Radev