Testing Inserts, Deletes and Updates before execution ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hagen Hoepfner

    #1

    Testing Inserts, Deletes and Updates before execution ...

    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?



  • Michael Paesold

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

    Hagen Hoepfner wrote:
    [color=blue]
    > 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.[/color]

    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 majordomo@postg resql.org

    Comment

    Working...