By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,777 Members | 1,755 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,777 IT Pros & Developers. It's quick & easy.

Testing Inserts, Deletes and Updates before execution ...

P: n/a
Dear list,

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.

Any ideas?

Hagen

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.