Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V3uTj-0000h1-Fi for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Jul 2013 20:55:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V3uTi-0000CG-U0 for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Jul 2013 20:55:38 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V3uTh-0000Al-MW for pgsql-bugs@postgresql.org; Mon, 29 Jul 2013 20:55:37 +0000 Received: from kazi6.fit.vutbr.cz ([2001:67c:1220:808::93e5:80c] helo=kazi.fit.vutbr.cz) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V3uTd-0005aT-SU for pgsql-bugs@postgresql.org; Mon, 29 Jul 2013 20:55:37 +0000 Received: from [10.0.0.100] (171.123.broadband2.iol.cz [83.208.123.171]) (authenticated bits=0) by kazi.fit.vutbr.cz (8.14.7/8.14.6) with ESMTP id r6TKtSDp001885 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 29 Jul 2013 22:55:29 +0200 (CEST) Message-ID: <51F6D6C0.1010503@fit.vutbr.cz> Date: Mon, 29 Jul 2013 22:55:28 +0200 From: Petr Chmelar User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: Pavel Stehule CC: Andrew Gierth , pgsql-bugs@postgresql.org Subject: Re: BUG #8329: UPDATE x SET x.y = x.y + z does not work in PL/pgSQL References: <51F17357.2030103@fit.vutbr.cz> <7f7d6be25f85517e14f6e957a7212e8f@news-out.riddles.org.uk> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.74 on 147.229.8.12 X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Dear Pavel and Andrew, avoiding the nulls solves the thing - thank you! I was considering NULL as 0... lame. I just wonder why it was working in the console, but it is not important - at the moment it works just fine. Cheers, Petr On 27.7.2013 22:59, Pavel Stehule wrote: > Hello > > 2013/7/27 Andrew Gierth : >> Seems clearly your mistake to me... you do realize that (null + z) is >> always going to be null, right? Maybe your totals columns should have >> been declared NOT NULL (and presumably DEFAULT 0) to avoid this >> problem? >> >> Adding some diagnostics to your function (and fixing all the syntax >> errors) and running it shows that you're frequently trying to add to >> nulls, e.g.: >> >> NOTICE: sum_pkt_in_int = >> NOTICE: sum_orig_raw_pktcount = 4 >> NOTICE: sum_pkt_in_int = >> NOTICE: sum_orig_raw_pktcount = 599 >> >> these diagnostics were obtained as follows: >> >> CREATE OR REPLACE FUNCTION statistics.notice(text, anyelement) >> RETURNS anyelement >> LANGUAGE plpgsql >> AS $function$ begin raise notice '% = %', $1, $2; return $2; end; $function$ >> >> and changing your update to: >> >> sum_pkt_in_int = notice(''sum_pkt_in_int'',sum_pkt_in_int) >> + notice(''sum_orig_raw_pktcount'',sum_orig_raw_pktcount), >> -- XXX THIS IS IT, does not work even when ... + 1000000 XXX >> >> (doing \set VERBOSITY terse in psql is a good idea for this case to >> avoid excessive CONTEXT output) >> >> -- >> Andrew (irc:RhodiumToad) >> > it is strange. I didn't find any problem on tested data, although a > bugs was displeasing. > > If query works from console, then planner is clearly ok, and possible > issue can be somewhere in plpgsql. But it should be located more > preciously. > > You can use a debug function or debug trigger > > CREATE OR REPLACE FUNCTION statistics.foo() > RETURNS trigger > LANGUAGE plpgsql > AS $function$ > begin > if new.sum_pkt_in_int is null then > raise notice 'attention, new is null'; > end if; > return new; > end; > $function$ > > create trigger xx before update on hosts1 for each row execute procedure foo(); > > Regards > > Pavel > > p.s. check if COALESCE helps, and then problem is somewhere in data probably > > sum can return null if all values are null > > postgres=# select sum(a) is null from (values(null::integer)) x(a); > ?column? > ---------- > t > (1 row) > > > > >> -- >> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-bugs -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs