Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i0NpE-0006uS-BQ for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Aug 2019 10:26:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i0NpC-00042l-TN for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Aug 2019 10:26:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i0NpC-00042e-IX for pgsql-bugs@lists.postgresql.org; Wed, 21 Aug 2019 10:26:42 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i0Np9-0007yQ-F3 for pgsql-bugs@lists.postgresql.org; Wed, 21 Aug 2019 10:26:41 +0000 Received: from [10.8.0.6] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPSA (Nemesis) id 1Mdvyi-1iZAPX27pW-00b6CR; Wed, 21 Aug 2019 12:26:33 +0200 Subject: Re: BUG #15971: Behaviour of SUBSTR function depending on its arguments To: pgsql-bugs@lists.postgresql.org References: <15971-965406c5a667c01a@postgresql.org> Cc: bvimalvictor@gmail.com From: Thomas Kellerer Message-ID: <89fff570-c391-26ef-49d6-b1e9afd3f5db@gmx.net> Date: Wed, 21 Aug 2019 12:26:30 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: <15971-965406c5a667c01a@postgresql.org> Content-Type: text/plain; charset=utf-8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l4ty RTp42yrmsCa7JTGlyg694OOrbr/PIf5gmGQRo0Mo9p3L6aKN2T6Y+hc30ps= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form schrieb am 21.08.2019 um 09:02: > select substr('abcdef',1,2) val1, substr('abcdef',0,2) val2, > substr('abcdef',-1,2) val3; > > The above query in Postgres returns expected result for val1 ('ab') but for > val2 and val3, it returns 'a' and '' respectively. Oracle and most of other > RDBMS systems would return 'ab' for val1 and val2. The only "other" DBMS that behaves the way you describe it, is Oracle. When I ran it on different systems, this is the result: | val1 | val2 | val3 | -----------|------|---------|---------| Postgres | ab | a | | SQL Server | ab | a | | SQLite | ab | a | f | MySQL | ab | | f | Oracle | ab | ab | f | DB2 and Firebird do not allow a starting position smaller than 1 So SQL Server works the same as Postgres and Oracle is the only one that returns 'ab' for the second case So clearly the claim "most other" is wrong here.