Thread: EXCEPTION clause not identified

EXCEPTION clause not identified

From
"Jasbinder Singh Bali"
Date:
Hi,
In one of my trigger functions, i'm trying to catch invalid ip address exception

CREATE OR REPLACE FUNCTION func_client_socket()
  RETURNS "trigger" AS
$BODY$
        DECLARE
                      ip_address_present int4;
BEGIN
                      ip_address_present = 1;
SELECT inet(NEW.canonical_name);
            EXCEPTION WHEN invalid_text_representation THEN
                    ip_address=0;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

when i run this function, it gives me the followin error

ERROR:  syntax error at or near "EXCEPTION" at character 1343
which is the line where I have the EXCEPTION clause.

Can anyone please tell me whats going wrong here?

Thanks,
~Jas

Re: EXCEPTION clause not identified

From
Tom Lane
Date:
"Jasbinder Singh Bali" <jsbali@gmail.com> writes:
> In one of my trigger functions, i'm trying to catch invalid ip address
> exception

> CREATE OR REPLACE FUNCTION func_client_socket()
>   RETURNS "trigger" AS
> $BODY$
>         DECLARE
>                       ip_address_present int4;
> BEGIN
>                       ip_address_present = 1;
> SELECT inet(NEW.canonical_name);
>             EXCEPTION WHEN invalid_text_representation THEN
>                     ip_address=0;
> END;
> $BODY$
>   LANGUAGE 'plpgsql' VOLATILE;

> when i run this function, it gives me the followin error

> ERROR:  syntax error at or near "EXCEPTION" at character 1343
> which is the line where I have the EXCEPTION clause.

When I run the function as given, it doesn't complain about the
EXCEPTION, but it does complain about the misspelled variable name
on the next line.  Maybe you miscounted lines?  It'd be worth your
while to update to a more recent PG version that gives better-localized
syntax error messages.  8.1 or 8.2 will say something like

ERROR:  syntax error at or near "ip_address" at character 1
QUERY:  ip_address=0
CONTEXT:  SQL statement in PL/PgSQL function "func_client_socket" near line 7
LINE 1: ip_address=0
        ^

            regards, tom lane

Re: EXCEPTION clause not identified

From
"Prashant Ranjalkar"
Date:
Hi,
 
Probably you might be using reserved words (ip_address). Please try with out using the reserved words.
 
Regards
Prashant Ranjalkar


 
On 5/14/07, Jasbinder Singh Bali <jsbali@gmail.com> wrote:
Hi,
In one of my trigger functions, i'm trying to catch invalid ip address exception

CREATE OR REPLACE FUNCTION func_client_socket()
  RETURNS "trigger" AS
$BODY$
        DECLARE
                      ip_address_present int4;
BEGIN
                      ip_address_present = 1;
SELECT inet(NEW.canonical_name);
            EXCEPTION WHEN invalid_text_representation THEN
                    ip_address=0;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

when i run this function, it gives me the followin error

ERROR:  syntax error at or near "EXCEPTION" at character 1343
which is the line where I have the EXCEPTION clause.

Can anyone please tell me whats going wrong here?

Thanks,
~Jas