Re: BUG #17450: SUBSTRING function extracting lesser characters than specified

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
Cc: Hubert Lubaczewski <depesz(at)depesz(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, ganguly(dot)04(at)gmail(dot)com, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17450: SUBSTRING function extracting lesser characters than specified
Date: 2022-03-28 14:09:23
Message-ID: CAKFQuwZ9=nQojnCdk3nVqaPUH1CQGvg2+w_H+U_xp+1vzMoPJQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Mar 28, 2022 at 5:35 AM Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
wrote:

> пн, 28 мар. 2022 г. в 15:01, hubert depesz lubaczewski <depesz(at)depesz(dot)com
> >:
>
>> 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(dot)04(at)gmail(dot)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
>>
>
You should reference the documentation you are basing your conclusion off
of for this kind of report.

This example in the documentation clearly demonstrates the 1-based nature
of the numbering:

substring('Thomas' from 2 for 3) → hom

as does this one:

substr('alphabet', 3, 2) → ph

https://www.postgresql.org/docs/current/functions-string.html

Oddly, I don't actually see a non-standard form of substring spelled that
way though indeed the example works.

Probably it should be backpatched into all versions having 4bd3fad80e5c
> i.e. since v11.
>

The behavior of the example command is identical both before and since v11
so I don't see how that commit has anything to do with this. Nor, as shown
above, does this contradict the documentation. The bug report is simply
wrong and you seem to have attempted to supply a fix without confirming it.

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Kapila 2022-03-29 11:27:42 Re: Logical replication stops dropping used initial-sync replication slots
Previous Message Pavel Borisov 2022-03-28 14:00:15 Re: BUG #17450: SUBSTRING function extracting lesser characters than specified