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

Re: insert/update

From: Paul Thomas <paul(at)tmsl(dot)demon(dot)co(dot)uk>
To: Tom Allison <tallison(at)tacocat(dot)net>
Cc: "pgsql-general (at) postgresql (dot) org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: insert/update
Date: 2004-05-26 11:37:11
Message-ID: 20040526123711.A10413@bacon (view raw or flat)
Thread:
Lists: pgsql-general
On 26/05/2004 11:54 Tom Allison wrote:
> I seemed to remember being able to do this but I can't find the docs.
> 
> Can I run a sql query to insert new or update existing rows in one query?
> 
> Otherwise I have to run a select query to see if it's there and then 
> another one to update/insert.
> 
> What I'm trying to do is create a counter for each key, insert a value 
> of 1 or increment the value by 1 and then set another specific row 
> (where key = $key) to always increment by 1.
> 
> And the more I type, the more this sounds like the answer is going to be 
> part function, part trigger....  Maybe I should post to 'novice' for a 
> while!  ;)

Use a sequence.

-- 
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for 
Business             |
| Computer Consultants         | 
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

In response to

Responses

pgsql-general by date

Next:From: Richard HuxtonDate: 2004-05-26 12:28:24
Subject: Re: insert/update
Previous:From: Tom AllisonDate: 2004-05-26 10:54:05
Subject: insert/update

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