Skip site navigation (1) Skip section navigation (2)

Re: Conditional INSERT: if not exists

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: Don Morrison <donmorrison(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Conditional INSERT: if not exists
Date: 2006-08-22 13:26:37
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Don Morrison wrote:
> I want to insert a row unless it exists already.  Do I have to write a
> stored procedure to do this?

Hi, Don.

Just do the insert.  If it already exists, it simply isn't inserted.  
You will, of course, receive an error that the row exists, but that 
isn't a problem.  If you need to do this in a transaction, you can 
simply set savepoints and roll back to the savepoint if an insert fails 
(and you expected that it could).


In response to


pgsql-novice by date

Next:From: ben sewellDate: 2006-08-22 13:57:15
Subject: Passing parameters to postgreSQL from MS Access 2000
Previous:From: Phillip SmithDate: 2006-08-22 01:20:40
Subject: Re: Conditional INSERT: if not exists

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group