Re: Testing Inserts, Deletes and Updates before execution ...

From: "Michael Paesold" <mpaesold(at)gmx(dot)at>
To: "Hagen Hoepfner" <Hagen(dot)Hoepfner(at)gmx(dot)de>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Testing Inserts, Deletes and Updates before execution ...
Date: 2004-10-10 12:05:07
Message-ID: 007601c4aec1$63a64a20$0a01a8c0@zaphod
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hagen Hoepfner wrote:

> i am looking for a way to check, whether an DML-statement can be
> performed on a current database. That means, that i want to check, if
> e.g. an INSERT is possible or not (due to existing constraints), without
> executing it.

I think this could be the easiest way: try it and rollback.

BEGIN;
SET CONSTRAINTS ALL IMMEDIATE; -- if you have deferred foreign key, e.g.
INSERT .... -- check if it works
ROLLBACK;

That should do what you want, IMHO.
In PostgreSQL 8.0 you would not need your own transaction here...

BEGIN;
-- do some work

SAVEPOINT check_dml;
INSERT ... -- check if it works
ROLLBACK TO check_dml;

-- do some more work
COMMIT;

Could this be what you want?

Best Regards,
Michael Paesold

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pierre-Frédéric Caillaud 2004-10-10 12:18:47 Re: OS not good for database
Previous Message Hagen Hoepfner 2004-10-10 11:18:21 Testing Inserts, Deletes and Updates before execution ...