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 BE48052A5C for ; Fri, 18 Mar 2005 16:30:07 +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 81325-04 for ; Fri, 18 Mar 2005 16:30:03 +0000 (GMT) Received: from floppy.pyrenet.fr (unknown [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id A1123565BD for ; Fri, 18 Mar 2005 16:30:02 +0000 (GMT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 5438E30EA0; Fri, 18 Mar 2005 17:30:01 +0100 (MET) From: "Greg Patnude" X-Newsgroups: pgsql.sql Subject: Re: best way to swap two records (computer details) Date: Fri, 18 Mar 2005 08:32:25 -0800 Organization: dataMosaics.com Lines: 84 Message-ID: References: <200503181325.23293.gary.stainburn@ringways.co.uk> Reply-To: "Greg Patnude" X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.264 tagged_above=0 required=5 tests=FORGED_HOTMAIL_RCVD2, PRIORITY_NO_NAME X-Spam-Level: ** X-Archive-Number: 200503/261 X-Sequence-Number: 20740 How about a user defined function ??? CREATE OR REPLACE FUNCTION harwareupdate(integer, integer) RETURNS BOOLEAN AS ' update pieces set p_name = \'LSALES1\', p_location = \'Mike Haley\', p_site = \'L\' where p_id = $1; update pieces set p_name = \'SPARE\', p_location = \'spare\', p_site = \'L\' where p_id = 2; update pieces set p_owner = $1 where p_owner = $2 and p_type in (select hwt_id from hw_types where hwt_cat in ( select hwc_id from hw_categories where hwc_hwg_id = 7 ) ); SELECT TRUE; ' LANGUAGE SQL; Then all you need to do is: SELECT * FROM updatehardware(724, 305); "Gary Stainburn" wrote in message news:200503181325.23293.gary.stainburn@ringways.co.uk... > Hi folks. > > I have a table called pieces which contain every piece of hardware and > software within my company. > > Each piece has an owner attribute which points to another piece which - > funnily enough - owns it. > > For example records for CPU, motherboard, HDD, O/S, and applications > will all be owned by a piece record representing a computer. > > I'm currently going through an upgrade process at the moment where I > build a new PC, install all relevent software and use Documents and > Settings Transfer Wizard to move a user onto the new PC before wiping > and disposing the old PC. > > 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). > > Currently I do this manually with: > > update pieces set p_name = 'LSALES1', p_location = 'Mike Haley', p_site > = 'L' where p_id = 724; > update pieces set p_name = 'SPARE', p_location = 'spare', p_site = 'L' > where p_id = 305; > > update pieces set p_owner = 724 where p_owner = 305 and p_type in ( > select hwt_id from hw_types where hwt_cat in ( > select hwc_id from hw_categories where hwc_hwg_id = 7)); > > The hw_types and hw_categories select all O/S and application software. > This doesn't put any software currently on 305 onto 724 which would be > nice. > > (I'm not after someone to do my work for me, but a good starting point > would be very much appreciated) > > -- > 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 > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings >