Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V8Rs5-0000vp-QJ for pgsql-bugs@arkaria.postgresql.org; Sun, 11 Aug 2013 09:23:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V8Rs5-00025L-21 for pgsql-bugs@arkaria.postgresql.org; Sun, 11 Aug 2013 09:23:33 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V8Rs2-00025C-VV for pgsql-bugs@postgresql.org; Sun, 11 Aug 2013 09:23:31 +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 1V8Rry-0000sH-Sd for pgsql-bugs@postgresql.org; Sun, 11 Aug 2013 09:23:30 +0000 Received: from [10.0.0.2] (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 r7B9NLG8063410 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Sun, 11 Aug 2013 11:23:21 +0200 (CEST) Message-ID: <52075809.5020903@fit.vutbr.cz> Date: Sun, 11 Aug 2013 11:23:21 +0200 From: Petr Chmelar User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 MIME-Version: 1.0 CC: 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> <51F6D6C0.1010503@fit.vutbr.cz> In-Reply-To: <51F6D6C0.1010503@fit.vutbr.cz> 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: -0.9 (/) 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 Hi, according to the previous thread, can you update the documentation, please: http://www.postgresql.org/docs/current/static/functions-math.html so there is clean what results do you get eg. on "NULL + 1" (and "1 + NULL"), which gives you null and it is different from sum(x), where it gives 1 where are NULL and 1 in column x. Probably you should introduce coalesce() here. Thank you, Petr On 29.7.2013 22:55, Petr Chmelar wrote: > 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