Re: [BUGS] Problem when adding an existing primary key

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: [BUGS] Problem when adding an existing primary key
Дата
Msg-id 200302031025.17581.josh@agliodbs.com
обсуждение исходный текст
Список pgsql-novice
Ricardo,

I've moved our discussion over to the NOVICE list, because the BUGS list is
not the appropriate place for it.

EVERYONE:  If anyone reading this speaks Brazillian Portuguese, please help
Ricardo out, ok?

> But what if I have a program and I want to show and error message to the
> user saying
> something like: "This registry already exists" and simply don't add?
> Instead, Postgres is
> closing the application! This should not happen. If I've got this message
> using psql OK,
> but inside my programs I should control the messages I what to display to
> the user, don't
> you think? Or, every time the user forget and insert a duplicated primary
> key, he will be
> obbligated to see postgres message?

That depends on how your application is written.  You can take three
approaches:

1) Anticipation:  You can have a script test for the primary key, and any
other required conditions of uniqueness, while the user's submission is still
in a buffer before calling an INSERT statement.

2) System-controlled keys:  You can have the system assign the primary key and
take it out of the user's hands, thus preventing duplicates.  In Postgres,
once does this using Sequences.

3) Error interception:  You can have your interface code intercept error
messages coming from Postgresql, match the text, and return to the user a
more user-friendly error message.

I generally take an approach that is a combination of 1) and 2).

Unless I'm completely misunderstanding you, though, you need to build up your
basic knowledge of database application design.  I do not know any books in
Brazillian, but for English, see the book review page:
http://techdocs.postgresql.org/techdocs/bookreviews.php

--
Josh Berkus
Aglio Database Solutions
San Francisco

В списке pgsql-novice по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [ADMIN] Database access problem : SOS
Следующее
От: Andrew McMillan
Дата:
Сообщение: Re: Can't connect to postgresql on win32 using Perl