Unique Indexes

Поиск
Список
Период
Сортировка
От ILove TheSpam
Тема Unique Indexes
Дата
Msg-id BAY9-F18A7235C27C2E5AA148B23C0530@phx.gbl
обсуждение исходный текст
Ответы Re: Unique Indexes  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-general
Hi,

I'm new to Postgres and plpgsql so my sincerest apologies if the answer to
my problem is common :-)
I want to add entries to a table. The table has 2 fields, FieldID which is
the primary key and FieldValue which is a unique field.
I can add to FieldValue just fine when the unique constraint hasn't been
breached. However, if I try to add to FieldValue and there's already another
field with that value, obviously I'll get an error.
My problem is that I want to:
a) Be able to detect when an error occurs and be able to read that error
b) Find out the FieldID for the row which already has the value in it. So if
I try to enter 'blah' into FieldValue and it's already in the row with
FieldID=3, I want the value 3 to be returned to me. I realise this can be
done using a SELECT after the error, but I'd like to avoid that. I'm hoping
Postgres itself has some way of detecting this sort of thing.

Even though I'm new to Postgres, I have looked at triggers and functions and
I'm feeling fairly confident with them, so please, if that's what it takes,
suggest it :-)

Thanks!

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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

Предыдущее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Best practices: Handling Daylight-saving time
Следующее
От: "Magnus Hagander"
Дата:
Сообщение: Re: VMWare and PostgreSQL: WAS :PostgreSQL still for Linux only?