Re: simple? query

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: simple? query
Date: 2009-08-14 14:53:16
Message-ID: m3ab22cuqr.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Relyea, Mike" <Mike(dot)Relyea(at)xerox(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Browne 2009-08-14 15:18:21 Re: mail alert
Previous Message Relyea, Mike 2009-08-14 14:21:55 Re: simple? query