pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Landscheidt <tim@tim-landscheidt.de>
To: pgsql-sql@postgresql.org
Subject: Re: simple? query
Date: Fri, 14 Aug 2009 14:53:16 +0000
Message-ID: <m3ab22cuqr.fsf@passepartout.tim-landscheidt.de> (raw)
References: <E30C7040DE22624185BAD4093190B54437BE5DB4C1@EX2007-MBX-2.uz.kuleuven.ac.be>
	<AF7D9319B29A0242A33C3BF843BD313308A204EB@USA7061MS03.na.xerox.net>
	<E30C7040DE22624185BAD4093190B54437BE5DB4D5@EX2007-MBX-2.uz.kuleuven.ac.be>
	<AF7D9319B29A0242A33C3BF843BD313308A20639@USA7061MS03.na.xerox.net>
	<E30C7040DE22624185BAD4093190B54437BE5DB4DE@EX2007-MBX-2.uz.kuleuven.ac.be>
	<AF7D9319B29A0242A33C3BF843BD313308A20682@USA7061MS03.na.xerox.net>

"Relyea, Mike" <Mike.Relyea@xerox.com> wrote:

>> The goal is, where uid not equals to 'janvleuven10' a new
>> record should be inserted with the uid, and registered=0

> So if a record is found you want to update it and if a record isn't
> found you want to insert it.  I think you'll probably want to use
> plpgsql http://www.postgresql.org/docs/8.4/static/plpgsql.html or some
> other language like Jasen suggested.  I don't know of a way to do this
> with straight sql.

Something along the lines of:

| UPDATE table SET attribute = 'something' WHERE primary_key = 'id';
| INSERT INTO table (primary_key, attribute) SELECT 'id', 'something' WHERE 'id' NOT IN (SELECT primary_key FROM table);

should achieve that.

Tim




view thread (12+ messages)  latest in thread

Message-ID: <m3ab22cuqr.fsf@passepartout.tim-landscheidt.de>
Permalink:  ../m3ab22cuqr.fsf@passepartout.tim-landscheidt.de/
Also on:    postgresql.org/message-id/m3ab22cuqr.fsf@passepartout.tim-landscheidt.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tim@tim-landscheidt.de
  Subject: Re: simple? query
  In-Reply-To: <m3ab22cuqr.fsf@passepartout.tim-landscheidt.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox