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

Re: INSERT OU UPDATE WITHOUT SELECT?

From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: "Dave Dutcher" <dave(at)tridecap(dot)com>
Cc: lists(at)peufeu(dot)com, pgsql-performance(at)postgresql(dot)org
Subject: Re: INSERT OU UPDATE WITHOUT SELECT?
Date: 2006-05-30 23:05:08
Message-ID: 20060530190508.aa47bafe.darcy@druid.net (view raw or flat)
Thread:
Lists: pgsql-performance
On Tue, 30 May 2006 17:54:00 -0500
"Dave Dutcher" <dave(at)tridecap(dot)com> wrote:
> What I do when I'm feeling lazy is execute a delete statement and then
> an insert.  I only do it when I'm inserting/updating a very small number
> of rows, so I've never worried if its optimal for performance.  Besides
> I've heard that an update in postgres is similar in performance to a
> delete/insert.

Well, they are basically the same operation in PostgreSQL.  An update
adds a row to the end and marks the old one dead.  A delete/insert
marks the row dead and adds one at the end.  There may be some
optimization if the engine does both in one operation.

-- 
D'Arcy J.M. Cain <darcy(at)druid(dot)net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

In response to

Responses

pgsql-performance by date

Next:From: Jim C. NasbyDate: 2006-05-31 00:38:17
Subject: Re: Why the 8.1 plan is worst than 7.4?
Previous:From: Dave DutcherDate: 2006-05-30 22:54:00
Subject: Re: INSERT OU UPDATE WITHOUT SELECT?

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