Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYn7l-0003sK-UP for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Mar 2022 11:01:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nYn7k-0000v9-Q1 for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Mar 2022 11:01:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYn7k-0000uy-Fs for pgsql-bugs@lists.postgresql.org; Mon, 28 Mar 2022 11:01:24 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYn7h-0001bb-V1 for pgsql-bugs@lists.postgresql.org; Mon, 28 Mar 2022 11:01:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:To:Sender:From:Date:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=g+e+JEGFz6lPV0/JP3x4WUOqcoV52lTrgTCg2y6HXu4=; b=VtCwhfR4/c0XhM2tEv2hdIgyYN vozAjJxqeE5wVZSTnNw0MH5W49PzTm3riD8ZBsDHmqXi8TId05hWWbYFRxptubbCzwdGnHb7qWAlY snCTrmfs6xoHf5btk8m0CxGaEEGjoF0MyOK5bShvRBw11K2sgLaFmRqmGKAv56kjzwMQ=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1nYn7g-00073v-5f; Mon, 28 Mar 2022 13:01:20 +0200 Date: Mon, 28 Mar 2022 13:01:20 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: ganguly.04@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17450: SUBSTRING function extracting lesser characters than specified Message-ID: <20220328110119.GA28018@depesz.com> Reply-To: depesz@depesz.com References: <17450-69df48455c28fbea@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <17450-69df48455c28fbea@postgresql.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Mar 28, 2022 at 10:30:07AM +0000, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 17450 > Logged by: Suman Ganguly > Email address: ganguly.04@gmail.com > PostgreSQL version: 10.17 > Operating system: x86_64-pc-linux-gnu > Description: > > select substring('123456', 0 , 5) > On running this, Postgres returns '1234' > Expecting '12345' to be returned as per the documentation Well, the problem is that you're trying to provide character number 0, which is leading to bad results. substring works on base-1 numbering. depesz