pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mario Splivalo <mario.splivalo@megafon.hr>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Trapping 'invalid input syntax for integer'
Date: Thu, 10 Sep 2009 14:23:07 +0200
Message-ID: <4AA8EFAB.8070509@megafon.hr> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <4AA8EFAB.8070509@megafon.hr>
Permalink:  ../4AA8EFAB.8070509@megafon.hr/
Also on:    postgresql.org/message-id/4AA8EFAB.8070509@megafon.hr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mario.splivalo@megafon.hr
  Subject: Re: Trapping 'invalid input syntax for integer'
  In-Reply-To: <4AA8EFAB.8070509@megafon.hr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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