From: | Jan Verheyden <jan(dot)verheyden(at)uz(dot)kuleuven(dot)ac(dot)be> |
---|---|
To: | "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | FW: simple? query |
Date: | 2009-08-18 07:04:42 |
Message-ID: | E30C7040DE22624185BAD4093190B54437BE5DB513@EX2007-MBX-2.uz.kuleuven.ac.be |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi,
Thanks for the suggestion, the only problem is, if primary key is used then each row should be unique what is not true; since I have a column 'registered' what only can be 1 or 0...
Regards,
Jan
-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Tim Landscheidt
Sent: Friday, August 14, 2009 4:53 PM
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] simple? query
"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
From | Date | Subject | |
---|---|---|---|
Next Message | W. Kinastowski | 2009-08-18 07:47:24 | operator contains in older Pgsql |
Previous Message | Yeb Havinga | 2009-08-17 12:49:09 | Multiple simultaneous queries on single connection |