Re: automatic update or insert

Поиск
Список
Период
Сортировка
От Daryl Richter
Тема Re: automatic update or insert
Дата
Msg-id 435E4373.7060607@brandywine.com
обсуждение исходный текст
Ответ на automatic update or insert  ("tobbe" <tobbe@tripnet.se>)
Список 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.
> 

Regardless of how you implemented it, this seems unwise.  You can never 
know, nor validate, that this quantity is definitely correct.  Why can't 
you just insert another row and then count them?

If this is a transient value you might be ok, but I generally wouldn't 
put it in a DB in that case anyway...

> 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

-- 
Daryl Richter
Platform Author & Director of Technology

((         Brandywine Asset Management          ) ( "Expanding the Science of Global Investing"  ) (
http://www.brandywine.com          ))
 



В списке pgsql-sql по дате отправления:

Предыдущее
От: Daryl Richter
Дата:
Сообщение: Re: Merging lines with NULLs (with example data)
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: writable joined view