Re: best way to swap two records (computer details)

From: PFC <lists(at)boutiquenumerique(dot)com>
To: "Gary Stainburn" <gary(dot)stainburn(at)ringways(dot)co(dot)uk>, "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: best way to swap two records (computer details)
Date: 2005-03-18 19:54:45
Message-ID: op.snumxjkpth1vuj@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> My question is what's the best way to swap settings between the two
> computer records and swap any software installed? Ideally I'd like it
> in the form of a function where I can pass the two p_id's and return a
> boolean reflecting success (true) or fail (false).

I'd say something like that (generic table names) :

If you're confident :
UPDATE stuff SET owner = (CASE IF owner='A' THEN 'B' ELSE 'A' END) WHERE
owner IN ('A','B')

If you're paranoid :
UPDATE stuff SET owner = (CASE IF owner='A' THEN 'B' ELSE IF owner='B'
THEN 'A' ELSE owner END) WHERE owner IN ('A','B')

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Leon Stringer 2005-03-18 21:07:51 Re: Consecutive row count query
Previous Message lucas 2005-03-18 19:10:58 Trigger with parameters