BUG #16804: substring() function returns "negative substring length" error when using a large length argument

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: rafiss(at)gmail(dot)com
Subject: BUG #16804: substring() function returns "negative substring length" error when using a large length argument
Date: 2021-01-04 17:48:20
Message-ID: 16804-f4eeeb6c11ba71d4@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16804
Logged by: Rafi Shamim
Email address: rafiss(at)gmail(dot)com
PostgreSQL version: 13.1
Operating system: MacOS 10.15.7
Description:

Reproduction steps:

1. Connect to any PostgreSQL database.
2. Run this query:
> select substring('string' from 2 for 2147483646);

Actual result:

2021-01-04 12:43:13.145 EST [85734] ERROR: negative substring length not
allowed
2021-01-04 12:43:13.145 EST [85734] STATEMENT: select substring('string'
from 2 for 2147483646)
negative substring length not allowed

Expected result:

I don't know if this is covered by these docs:
https://www.postgresql.org/docs/13/functions-string.html
But I would expect one of the following:
1. There should be no error message, and the result should be 'tring'.
(Meaning it just goes to the end of the string.)
2. An error message that says that the length argument is too long.

I don't know what the SQL standard says, but when I try similar queries with
SQLite and MSSQL, the result is 'tring'.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander Lakhin 2021-01-04 18:00:00 Re: BUG #16774: PostgreSQL clean build MINGW64 gcc but initdb fails, cannot find startadress CreateProcessAsUserA
Previous Message PG Bug reporting form 2021-01-04 14:53:12 BUG #16803: create a table only one text/varchar column, storage options toast_tuple_target doesn't work