Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 843BC2AB7EA for ; Fri, 17 Feb 2012 03:52:32 -0400 (AST) Received: from vanguard.eglobalreach.net ([202.124.128.4]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RyIcH-0001ph-7S for pgsql-sql@postgresql.org; Fri, 17 Feb 2012 07:52:31 +0000 Received: from [172.16.10.215] (intra.eglobalreach.net [202.124.138.210]) by vanguard.eglobalreach.net (8.13.8/8.13.8) with ESMTP id q1H7qDci016221 for ; Fri, 17 Feb 2012 15:52:13 +0800 Message-ID: <4F3E072D.8030806@eglobalreach.net> Date: Fri, 17 Feb 2012 15:52:13 +0800 From: John Tuliao User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.26) Gecko/20120131 Thunderbird/3.1.18 MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: How can I use this subselect properly in an update? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.6 (-) X-Archive-Number: 201202/58 X-Sequence-Number: 36351 select substring(t1.called_number from t2.offset), t1.called_number from calls_join as t1, john_prefix as t2 where strpos(t1.called_number, t2.prefix) = '1' order by length(t2.prefix) desc limit '1' ; I'm having trouble using this as a sub-select in an UPDATE. Most of the time it works. Then sometimes it doesn't. Is there an issue with possible NULL values that can be found on table1 (t1)?