X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D534153582 for ; Wed, 23 Mar 2005 17:32:24 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 58186-09 for ; Wed, 23 Mar 2005 17:32:19 +0000 (GMT) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by svr1.postgresql.org (Postfix) with ESMTP id A0D44534CC for ; Wed, 23 Mar 2005 17:32:17 +0000 (GMT) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 1DE9dg-0008F3-00 for pgsql-sql@postgresql.org; Wed, 23 Mar 2005 17:27:28 +0000 Content-Type: text/plain; charset="iso-8859-15" From: Gary Stainburn Organization: Ringways Garages Ltd To: "'pgsql-sql@postgresql.org'" Subject: Re: best way to swap two records (computer details) Date: Wed, 23 Mar 2005 17:26:06 +0000 User-Agent: KMail/1.4.3 References: <200503181325.23293.gary.stainburn@ringways.co.uk> In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200503231726.06583.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/315 X-Sequence-Number: 20794 On Friday 18 March 2005 7:54 pm, you wrote: > > 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') Hello again. I've tried the first one but get a syntax error. Anyone see why? hardware=# update pieces set p_owner = (case if p_owner = 305 then 724 else 305 end) where p_owner in (305, 724); ERROR: parser: parse error at or near "p_owner" hardware=# -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000