Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id D458E9FBC20 for ; Thu, 8 Mar 2007 19:18:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 00791-04 for ; Thu, 8 Mar 2007 19:17:55 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id 779799FBBF1 for ; Thu, 8 Mar 2007 19:17:58 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so1056550ugf for ; Thu, 08 Mar 2007 15:17:57 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=jgZL4U9df1Jrrw5DnD+sHhpYvF9BOpFq+ARc/UOUmY5w+YXDN9rf/atofgZb8FUfJxCAYUfoDrXSTS4LSLian7K763nk+znCmhN7N0Av/FHY0qdSTTfsR2KA2RFKi//9Yn1QUIHsWTnOguAGfPNxfgp1UnsVNAN8uuPWld94Mjk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=kxQgpzuFLMqCTHEMhedhv1RPHLY9IlrIDDckxjcxDG1IrZgypU0zJSU1h2erKATjyNeUw9NobnI/z4wUZOX7/gcyAa8opN9gECUtOwgvGRlzxLc62n23eGljWMoTrY40TOSccv02lpflBhZNMgq3Hw05hspmHMQQ2Yry2XygG4I= Received: by 10.67.29.12 with SMTP id g12mr8037211ugj.1173395876431; Thu, 08 Mar 2007 15:17:56 -0800 (PST) Received: from ?192.168.1.34? ( [82.3.248.250]) by mx.google.com with ESMTP id b33sm5548546ika.2007.03.08.15.17.52; Thu, 08 Mar 2007 15:17:55 -0800 (PST) Message-ID: <45F099A0.5080401@enterprisedb.com> Date: Thu, 08 Mar 2007 23:17:52 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.8 (X11/20061116) MIME-Version: 1.0 To: Steve CC: pgsql-performance@postgresql.org Subject: Re: Question about PGSQL functions References: <20070308084823.GA7216@svr2.hagander.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/179 X-Sequence-Number: 23584 Steve wrote: > IF strlen(source.corrected_procedure_code) > THEN: > summary.procedure_code=source.corrected_procedure_code > summary.wrong_procedure_code=source.procedure_code > ELSE: > summary.procedure_code=source.procedure_code > summary.wrong_procedure_code=NULL Um, so you test if source.corrected_procedure_code is an empty string? And if it is, summary.procedure_code is set to an empty string? But in wrong_procedure_code, you use NULLs? > Simple, right? Making a C function to handle this should be no sweat -- > I would basically split this logic into two separate functions, one to > populate summary.procedure_code and one to populate > summary.wrong_procedure_code, and it removes the need of having any sort > of back and forth between the program and DB... I can just do like: > > update summary_table > set procedure_code=pickCorrect(source.procedure_code, > source.corrected_procedure_code), > wrong_procedure_code=pickWrong(source.procedure_code, > source.corrected_procedure_code),.... > from source where summary_table.source_id=source.source_id; ISTM you could write this easily with a little bit of SQL, with no need for C-functions (I haven't run this, probably full of typos..) : update summary_table set procedure_code = (CASE WHEN source.corrected_procedure_code = '' THEN '' ELSE source.procedure_code END;), wrong_procedure_code = (CASE WHEN source.corrected_procedure_code = '' THEN source.procedure_code ELSE NULL END;) from source where summary_table.source_id=source.source_id; -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com