Re: EXCEPTION clause not identified

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jasbinder Singh Bali" <jsbali(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: EXCEPTION clause not identified
Date: 2007-05-14 13:20:30
Message-ID: 9192.1179148830@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Jasbinder Singh Bali" <jsbali(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paula Ta-Shma 2007-05-14 13:35:56 migrating a tablespace between postgres instances in shared disk environment
Previous Message Alban Hertroys 2007-05-14 13:05:59 Re: Streaming large data into postgres [WORM like applications]