Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhhtl-00CxBp-IW for pgsql-docs@arkaria.postgresql.org; Wed, 06 Mar 2024 03:24:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rhhti-004vZ6-TX for pgsql-docs@arkaria.postgresql.org; Wed, 06 Mar 2024 03:24:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhhti-004vYy-Kw for pgsql-docs@lists.postgresql.org; Wed, 06 Mar 2024 03:24:51 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhhtf-0034Qx-7l for pgsql-docs@lists.postgresql.org; Wed, 06 Mar 2024 03:24:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=2deU/hOTR5ANHJN58fG/7RYFODszk6xxNwIo8jJI95w=; b=SoP0u OEUe1nYnIaR2P+hQc6OLAAq4D7b1WtlJ/IAsbAzCEeydbGN9xD8FRKmvPkmntFOE5FQGwX3YO9q4T tAtG9qvfIHCXu71Tovsh7wpyR+9/GbYf6Oe7vsFIgX54Q5o5ssarXC0nRUS9k0YzUHpX0oWbLwDyu nn8FcdSIw1+SPEPIfiUpcFLNt02Ou5khDLO/LDwSJVn9Y5ETq4Jfhgq2mogvpSVvb7bZtv8PEu8mb nij3eYaq3wYAAU7Uy9tg6ziUTnVxrHGGS7EsKQIxmpQfndUQplJZ9J47Nqup+ujXQ25RlJmYUrwkT K1sUWP0q/rxHdYjpS9ZUMRPLr9gIQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1rhhtf-001dKQ-18; Tue, 05 Mar 2024 22:24:47 -0500 Date: Tue, 5 Mar 2024 22:24:47 -0500 From: Bruce Momjian To: dansonlinepresence@gmail.com Cc: pgsql-docs@lists.postgresql.org Subject: Re: substring start position behavior Message-ID: References: <170905442373.643.11536838320909376197@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="eIfhde6b4jPE7TMz" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --eIfhde6b4jPE7TMz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Mar 5, 2024 at 09:47:54PM -0500, dansonlinepresence@gmail.com wrote: > Thanks for all that context and diff! The odd behavior is indeed in > the SQL spec. At least I was convinced of that on postgres IRC by > someone who seemed to have quoted from the spec. I don't think the > feature ought to be hidden because it's odd. > > If I may suggest some specificity to the wording here, I think "start > values less than 1" would avoid confusion about whether 0 is > nonpositive or not, and bring attention to the function being > 1-indexed rather than 0-indexed. Sure, updated patch attached. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --eIfhde6b4jPE7TMz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="substring.diff" diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index e5fa82c161..f981793f00 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -2783,6 +2783,13 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in specified. Provide at least one of start and count. + + start values less then one specify + a start position before the first character, and therefore + count must be two greater than the absolute + value of start to begin returning characters + from the start of the string. + substring('Thomas' from 2 for 3) hom @@ -2794,6 +2801,10 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in substring('Thomas' for 2) Th + + + substring('Thomas' from -4 for 8) + Tho --eIfhde6b4jPE7TMz--