Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 089E51259185 for ; Fri, 27 Jan 2012 15:13:29 -0400 (AST) Received: from news.hub.org ([200.46.204.72]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RqrEj-00065G-Qz for pgsql-sql@postgresql.org; Fri, 27 Jan 2012 19:13:30 +0000 Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id q0RJDBJo022933 for ; Fri, 27 Jan 2012 15:13:11 -0400 (AST) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id q0RJ4S0o016316 for pgsql-sql@postgresql.org; Fri, 27 Jan 2012 15:04:28 -0400 (AST) (envelope-from news) From: Lew X-Newsgroups: pgsql.sql Subject: Re: Query question Date: Fri, 27 Jan 2012 11:04:25 -0800 Organization: albasani.net Lines: 54 Message-ID: References: <4F214065.8080201@htechcorp.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: news.albasani.net; logging-data="Tji4B+vtKSGFyHFun0S8e8acKWksaXoV2wlqiTDRysuDJx1WKwPt96F7taZy3PU3jriEetbx6iOeM6oDABDTrLw2Ul4Y8ok+AnuhlmMwkzpQO4McpTR7kCMnFchwMHtr"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0 In-Reply-To: <4F214065.8080201@htechcorp.net> Cancel-Lock: sha1:zd6W5bLz9MXa+PcnBLFfG0DkmCg= To: pgsql-sql@postgresql.org X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/109 X-Sequence-Number: 36280 On 01/26/2012 04:00 AM, John Tuliao wrote: > I seem to have a problem with a specific query: > > The inside query seems to work on it's own: > > select prefix > from john_prefix > where strpos(jpt_test.number,john_prefix.prefix) = '1' > order by char_length(john_prefix.prefix) desc limit 1 > > but when I execute it with this: > > UPDATE > jpt_test > set > number = substring(number from length(john_prefix.prefix)+1) > from > john_prefix > where > prefix in ( > select prefix > from john_prefix > where strpos(jpt_test.number,john_prefix.prefix) = '1' > order by char_length(john_prefix.prefix) desc limit 1 > ) ; > > table contents are as follows > > john_prefix table: > > prefix > --------- > 123 > 234 > > jpt_test table: > > number > ----------- > 1237999999 > 0234999999 <<< supposed to have no match > 2349999999 > > Am I missing something here? Any help will be appreciated. I'm going to guess that it's because you didn't use a separate alias for the FROM in the correlated subquery. Doesn't STRPOS() return INTEGER, not TEXT? -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg