From: Craig Ringer <craig@postnewspapers.com.au>
To: Maxime Lévesque <maxime.levesque@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: sending a block through jdbc
Date: Sun, 02 May 2010 08:25:51 +0800
Message-ID: <4BDCC68F.8000003@postnewspapers.com.au> (raw)
In-Reply-To: <741db998-8a4f-4442-930f-46821ff785d2@b18g2000yqb.googlegroups.com>
References: <741db998-8a4f-4442-930f-46821ff785d2@b18g2000yqb.googlegroups.com>
On 1/05/2010 11:20 AM, Maxime Lévesque wrote:
> I want to drop a constraint if it exists, and not get an error if it
> doesn't exist
Check the system tables / INFORMATION SCHEMA to test if it exists before
dropping it.
> ideally I'd get a jdbc error code, and silence the 'consrtaint does
> not exist' exception,
> but since postgress doesn't send error codes to jdbc, I'd like to put
> the statement in
Yes, it does. As Kris noted, it's in SQLException. Use the "getSQLState"
method. It's often useful to test for prefixes.
http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html#JDBC209http://www.postgresql.org/docs/current/interactive/errcodes-appendix.html> a block and silence the exception like this
>
> sb.append("begin \n");
> sb.append("alter table " + foreingKeyTable.name + " drop
> constraint " + fkName + ";\n");
> sb.append("exception when true then \n");
Exception handlers are a part of the PL/PgSQL language. They're not
supported in SQL, and don't make much sense there since there's no
procedural logic flow.
Kris pointed out that something similar is possible in 9.0. Consider
whether it's actually a good idea, though. DO blocks won't be cheap to
execute - especially compared to plain old SQL.
--
Craig Ringer
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: craig@postnewspapers.com.au, maxime.levesque@gmail.com
Subject: Re: sending a block through jdbc
In-Reply-To: <4BDCC68F.8000003@postnewspapers.com.au>
References: <741db998-8a4f-4442-930f-46821ff785d2@b18g2000yqb.googlegroups.com> <4BDCC68F.8000003@postnewspapers.com.au>
* 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