From: | "Alex Hunsaker" <badalex(at)gmail(dot)com> |
---|---|
To: | Dinesh <dbhandary(at)mongonet(dot)net> |
Cc: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org |
Subject: | Re: error handling unique key constraint in pgsql |
Date: | 2008-06-10 21:38:50 |
Message-ID: | 34d269d40806101438k3fe3833k48ff9e0224b1cbee@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Tue, Jun 10, 2008 at 2:46 PM, Dinesh <dbhandary(at)mongonet(dot)net> wrote:
> Hi Scott,
>
> Thanks for your reply.
>
> Is there a built in exception in pl/pgsql ( similar to oracle's
> |DUP_VAL_ON_INDEX ) that I can use?
>
> I ran into an unique situation a couple of days ago. Procedure that inserts
> a new value into unique index column was called at the same time. I even
> check if the value exist before inserting, but one of the instance of the
> function gave me an unique constraint violation error.
>
> My code looks like this:
>
> select into var * from table;
>
> if not found then
> insert into table
> values (a);
> end if;
> |
> I would imagine the postgres db would inherently handle situation like this,
> but it did not.
>
> Thanks.
See http://www.postgresql.org/docs/8.3/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING,
specifically example Example 38-1.
From | Date | Subject | |
---|---|---|---|
Next Message | Dinesh | 2008-06-10 21:54:55 | Re: error handling unique key constraint in pgsql |
Previous Message | Dinesh | 2008-06-10 20:46:25 | Re: error handling unique key constraint in pgsql |