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

Update on existence?

From: Jan Danielsson <jan(dot)m(dot)danielsson(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Update on existence?
Date: 2007-04-05 00:48:40
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Hello all,

   I have a table called sessions, with session ids. Each session also
has a last_access timestamp and some other data. Is is possible (using
PL/pgSQL) to implement something along the line of:

  select id, username, settings from sessions where id='foobar'
  If a result was found
     update sessions set last_access=current_timestamp where id='foobar'

   Obviously, I want to access the id, username and settings columns if
they are found.

   In other words: Is it possible to make something which behaves almost
like a normal "select", but which has some hidden internal magic as
described above?

Kind regards,
Jan Danielsson


pgsql-novice by date

Next:From: Richard Broersma JrDate: 2007-04-05 02:56:26
Subject: Re: Update on existence?
Previous:From: Mark KellyDate: 2007-04-04 22:52:15
Subject: Re: Design advice needed.

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