Re: "Upcalls" (sort of) from the database

From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "Don Y" <pgsql(at)dakotacom(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: "Upcalls" (sort of) from the database
Date: 2006-04-06 17:13:20
Message-ID: 758d5e7f0604061013q54b475e8g5487db26838ebcb0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4/6/06, Don Y <pgsql(at)dakotacom(dot)net> wrote:
>
> For example, the title may match an existing entry -- but
> the author may be different (e.g., misspelled, or some
> "other" author listed on a book having multiple authors, etc.).
> Ideally, I would like the database to suspend the INSERT,
> ask for confirmation (and "why") and then, either commit
> the INSERT or abort it (based on the user's response).
>
> Nearest I can imagine, there's only one ways I can do this:
> issue a query that looks for these types of problems and
> based on the result, let the *application* prompt the
> user for confirmation. Then, *if* confirmed, do the real
> INSERT.
>
> Is there a more elegant way?

Well, your application could:
BEGIN TRANSACTION;
Then it would
INSERT INTO... or call a stored procedure. The triggers/stored procedure
would
do all what's needed to perform such action, but when it notices something
suspicious it would RAISE (see PLpgSQL) a notice describing the problem(s).

If your user application notices such messages, it issues a message
"WARNING:
the message, do you want to continue?" and if user presses yes, you
do COMMIT. Otherwise you do ROLLBACK.

The thing is to use
http://www.postgresql.org/docs/8.1/static/plpgsql-errors-and-messages.html

Regards,
Dawid

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Diego Manilla Suárez 2006-04-06 17:14:50 Database lost after reboot
Previous Message Don Y 2006-04-06 17:12:02 Re: "Upcalls" (sort of) from the database