pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedTrapping 'invalid input syntax for integer'
3+ messages / 2 participants
[nested] [flat]
* Trapping 'invalid input syntax for integer'
@ 2009-09-10 12:23 Mario Splivalo <mario.splivalo@megafon.hr>
2009-09-10 13:54 ` Re: Trapping 'invalid input syntax for integer' Marcin Krawczyk <jankes.mk@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Mario Splivalo @ 2009-09-10 12:23 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Trapping 'invalid input syntax for integer'
2009-09-10 12:23 Trapping 'invalid input syntax for integer' Mario Splivalo <mario.splivalo@megafon.hr>
@ 2009-09-10 13:54 ` Marcin Krawczyk <jankes.mk@gmail.com>
2009-09-10 14:13 ` Re: Trapping 'invalid input syntax for integer' Mario Splivalo <mario.splivalo@megafon.hr>
0 siblings, 1 reply; 3+ messages in thread
From: Marcin Krawczyk @ 2009-09-10 13:54 UTC (permalink / raw)
To: Mario Splivalo <mario.splivalo@megafon.hr>; +Cc: 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.splivalo@megafon.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@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Trapping 'invalid input syntax for integer'
2009-09-10 12:23 Trapping 'invalid input syntax for integer' Mario Splivalo <mario.splivalo@megafon.hr>
2009-09-10 13:54 ` Re: Trapping 'invalid input syntax for integer' Marcin Krawczyk <jankes.mk@gmail.com>
@ 2009-09-10 14:13 ` Mario Splivalo <mario.splivalo@megafon.hr>
0 siblings, 0 replies; 3+ messages in thread
From: Mario Splivalo @ 2009-09-10 14:13 UTC (permalink / raw)
To: Marcin Krawczyk <jankes.mk@gmail.com>; +Cc: pgsql-sql
Marcin Krawczyk wrote:
> Hi, I believe you're looking for invalid_text_representation.
>
> EXCEPTION WHEN invalid_text_representation THEN
>
Thnx, that is it.
Mike
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2009-09-10 14:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-09-10 12:23 Trapping 'invalid input syntax for integer' Mario Splivalo <mario.splivalo@megafon.hr>
2009-09-10 13:54 ` Marcin Krawczyk <jankes.mk@gmail.com>
2009-09-10 14:13 ` Mario Splivalo <mario.splivalo@megafon.hr>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox