X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3A15352828 for ; Fri, 17 Jun 2005 07:25:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74568-09 for ; Fri, 17 Jun 2005 10:25:18 +0000 (GMT) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by svr1.postgresql.org (Postfix) with ESMTP id CD3995280D for ; Fri, 17 Jun 2005 07:25:16 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de with ESMTP (Nemesis), id 0ML2Dk-1DjE2I2zbv-0003z2; Fri, 17 Jun 2005 12:25:18 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1DjE2S-0007Mz-00 for pgsql-sql@postgresql.org; Fri, 17 Jun 2005 12:25:28 +0200 Date: Fri, 17 Jun 2005 12:25:28 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: [despammed] substr or char_length problem Message-ID: <20050617102528.GD15166@webserv.wug-glas.de> Mail-Followup-To: Andreas Kretschmer , pgsql-sql@postgresql.org References: <014a01c57323$90b72b20$b8e58bd5@cerit> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <014a01c57323$90b72b20$b8e58bd5@cerit> X-DEST: 208 X-MSMail-Priority: High X-Message-Flag: Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) X-PrivatMail: kretschmer@kaufbach.delug.de X-OS: Linux - weil ich es mir Wert bin! X-Info: registrierter Linux-User 97922 http://counter.li.org User-Agent: mutt-ng 1.5.9i (Linux) X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.311 tagged_above=0 required=5 tests=AWL, MISSING_MIMEOLE, X_MSMAIL_PRIORITY_HIGH X-Spam-Level: X-Archive-Number: 200506/217 X-Sequence-Number: 21818 am 17.06.2005, um 13:01:15 +0300 mailte Fatih Cerit folgendes: > Dear ALL > > I have a problem with function substr or char_length or both. I guery A2 > and it works fine. But sometimes gives 'ERROR: negative substring length > not allowed'. When I test many many times with diffrent values, never gives > error. Sample table and query below. > > > > A1 A2 > ------------------- > 1 1957 > 2 197 > 3 19 > 4 > 5 NULL > 6 1 > 7 195 > > > Select * from tbl_xxx where > tbl_xxx.A2=substr('196895588454554545454',0,char_length(tbl_xxx.A2)+1); Perhaps because char_length() returns NULL and this is a invalid value for substr(). Use coalesce(): ... substr('196895588454554545454',0,coalesce(char_length(tbl_xxx.A2),0)+1); Regards, Andreas -- Andreas Kretschmer (Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net === Schollglas Unternehmensgruppe ===