From: | Patrick JACQUOT <patrick(dot)jacquot(at)anpe(dot)fr> |
---|---|
To: | tobbe <tobbe(at)tripnet(dot)se> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: automatic update or insert |
Date: | 2005-10-26 07:53:52 |
Message-ID: | 435F3610.3020303@anpe.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2005-10-26 08:31:48 | Re: broken join optimization? (8.0) |
Previous Message | Kenneth Gonsalves | 2005-10-26 07:49:36 | Re: why vacuum |