EXCEPTION clause not identified

Started by Jasbinder Balialmost 19 years ago3 messagesgeneral
Jump to latest
#1Jasbinder Bali
jsbali@gmail.com

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jasbinder Bali (#1)
Re: EXCEPTION clause not identified

"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

#3Prashant Ranjalkar
prashant.ranjalkar@gmail.com
In reply to: Jasbinder Bali (#1)
Re: EXCEPTION clause not identified

Hi,

Probably you might be using reserved words (ip_address). Please try with out
using the reserved words.

Regards
Prashant Ranjalkar

Show quoted text

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