How can I do an UPDATE OR CREATE ?

Started by Guy Fraserover 26 years ago2 messagesgeneral
Jump to latest
#1Guy Fraser
guy@incentre.net

Hi

I am trying to figure out how I can create an entry if one does not
exist when attempting an update.

This kind of what I want to do :

if (select "User-Name","Realm" from details;) {
update details set "Time-Used" = old."Time-Used" +
new."Time-Used";
} else {
insert into details "User-Name","Realm","Time-Used";
}

I have not seen any documentation specifying what pragmatic operators
are available if any.

Thank You In Advance

Guy Fraser
mailto:guy@incentre.net

#2Stephen Boyle
yd80@dial.pipex.com
In reply to: Guy Fraser (#1)
Re: [GENERAL] How can I do an UPDATE OR CREATE ?

Guy,

I would think a plpgsql (or other) procedural language function would be the
easiest way to do this. Look at procedural languages and triggers in the
documentation.

Regards

Steve Boyle
-----Original Message-----
From: Guy Fraser <guy@incentre.net>
To: pgsql-general@postgreSQL.org <pgsql-general@postgreSQL.org>
Date: 21 July 1999 10:29
Subject: [GENERAL] How can I do an UPDATE OR CREATE ?

Show quoted text

Hi

I am trying to figure out how I can create an entry if one does not
exist when attempting an update.

This kind of what I want to do :

if (select "User-Name","Realm" from details;) {
update details set "Time-Used" = old."Time-Used" +
new."Time-Used";
} else {
insert into details "User-Name","Realm","Time-Used";
}

I have not seen any documentation specifying what pragmatic operators
are available if any.

Thank You In Advance

Guy Fraser
mailto:guy@incentre.net