Re: Conditional Adding to a Table

From: Allan Engelhardt <allane(at)cybaea(dot)com>
To: Glenn Sullivan <glenn(dot)sullivan(at)varianinc(dot)com>
Subject: Re: Conditional Adding to a Table
Date: 2001-10-11 19:04:11
Message-ID: 3BC5ED2B.9511CA2@cybaea.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You could use a LOCK TABLE statement to gain an exclusive lock, but a better approach is probably to put a unique constraint on whatever your check is and then just attempt the INSERT.

Hope this helps a little....

Allan.

Glenn Sullivan wrote:

> Greetings,
>
> I need to check a table to see if an item already exist in the table.
> It if does not, then I want to add it. Unfortunately, multiple processes
> (Solaris system) can be running at the same time. Sometimes, one process
> checks to see if an item exist and it does not. At the same time another
> process checks to see if the same item exist and it does not. Then both,
> add the item to the table. This is, of course, not what I want.
>
> I cannot seem to figure out how to do a conditional test to do something
> like this. If I could, then the whole operation could fit in one transaction
> with locking.
>
> Any ideas?
>
> Thanks,
> Glenn
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Allan Engelhardt 2001-10-11 19:17:28 Re: error codes when running pg_dumpall from a perl script.
Previous Message Gaurav Priyolkar 2001-10-11 17:36:40 "Relation x does not exist" error when x does exist