pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Patrick JACQUOT <patrick.jacquot@anpe.fr>
To: tobbe <tobbe@tripnet.se>
Cc: pgsql-sql@postgresql.org
Subject: Re: automatic update or insert
Date: Wed, 26 Oct 2005 09:53:52 +0200
Message-ID: <435F3610.3020303@anpe.fr> (raw)
In-Reply-To: <1129790184.351579.302550@g47g2000cwa.googlegroups.com>
References: <1129790184.351579.302550@g47g2000cwa.googlegroups.com>

tobbe wrote:

>Hi.
>
>I have a little problem.
>
>In a system of mine i need to insert records into table [tbStat], and
>if the records exist i need to update them instead and increase a
>column [cQuantity] for every update.
>
>I.e. the first insert sets cQuantity to 1, and for every other run
>cQuantity is increased.
>
>Currently i have implemented this as a stored procedure in the plpgsql
>language. This means that in my stored procedure i first do a select to
>find out if the row exists or not, then i do a insert or update
>depending if the row existed.
>
>Unfortunately, stored procedures seems awfully slow. And i need the
>application to go faster.
>
>One solution could be to implement the stored procedure in my program
>instead. I think that this will be atleast 50% faster than my stored
>procedure, so that would be ok.
>
>However, this has made me thinking. Couldn't this be done directly in
>SQL?
>
>
>Brgds Robert
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
>
>  
>
Maybe would it be better to insert always, and to use grouping and 
summation when using the table. That would enable you to preserve the 
history of events.
That's how I almost always work
hth
P.Jacquot



view thread (6+ messages)

Message-ID: <435F3610.3020303@anpe.fr>
Permalink:  ../435F3610.3020303@anpe.fr/
Also on:    postgresql.org/message-id/435F3610.3020303@anpe.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: patrick.jacquot@anpe.fr, tobbe@tripnet.se
  Subject: Re: automatic update or insert
  In-Reply-To: <435F3610.3020303@anpe.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox