From: | Yan Cheng Cheok <yccheok(at)yahoo(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Make sure there is no two column with same value - What is the best practice? |
Date: | 2010-02-12 08:17:05 |
Message-ID: | 732344.21578.qm@web65701.mail.ac4.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello, currently, I would like to make sure :
(1) When insert a new item, there is no 2nd row with same column value.
(2) If there is, I will just directly take the existing row.
I was thinking out of 2 approach. May I know which one is the common used best practice?
// Shall I make the **entire** procedure atomic and synchronized.
// This means, every time, there is only
// one thread can execute it. But, does PostgreSQL provide such features?
//
stored_procedure
{
if (column.value is not "Mickey Mouse") {
insert new row with one of the column.value is "Mickey Mouse"
}
return row id with its column.value is "Mickey Mouse"
}
stored_procedure
{
// I make this column.value to be unique
if (column.value is not "Mickey Mouse") {
try {
insert new row with one of the column.value is "Mickey Mouse"
}
catch (Is Not Unique Exception) {
}
}
return row id with its column.value is "Mickey Mouse"
}
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2010-02-12 08:26:52 | Re: Postgres standard versus Postgres Plus Advanced Server |
Previous Message | Magnus Hagander | 2010-02-12 08:09:33 | Re: Postgres standard versus Postgres Plus Advanced Server |