From: | Marcin Krawczyk <jankes(dot)mk(at)gmail(dot)com> |
---|---|
To: | Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr> |
Cc: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Trapping 'invalid input syntax for integer' |
Date: | 2009-09-10 13:54:47 |
Message-ID: | 95f6bf9b0909100654p3b5e31b3nb6174b3482eb51b3@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi, I believe you're looking for invalid_text_representation.
EXCEPTION WHEN invalid_text_representation THEN
regards
mk
2009/9/10 Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>
> Is there a way to trap this error in plpgsql code?
>
> I have a function that accepts integer and character varying. Inside
> that function I need to cast that varchar to integer. Of course,
> sometimes that is not possible.
> When I run function like that, I get this errror:
>
> fidel=# select * from get_account_info_by_tan(1, 'mario');
> ERROR: invalid input syntax for integer: "mario"
> CONTEXT: SQL statement "SELECT user_id FROM user_tans WHERE user_tan =
> $1 ::bigint"
> PL/pgSQL function "get_account_info_by_tan" line 8 at assignment
>
> Now, I know I could change the SELECT so it looks like:
>
> SELECT user_id FROM user_tans WHERE user_tan::varchar = $1
>
> But, is there a way to trap above error usin EXCEPTION WHEN keyword in
> plpgsql?
>
> Mike
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
From | Date | Subject | |
---|---|---|---|
Next Message | Mario Splivalo | 2009-09-10 14:13:22 | Re: Trapping 'invalid input syntax for integer' |
Previous Message | Rstat | 2009-09-10 13:00:18 | Talend : Talend Integration Suite vs Talend Open Studio |