Skip to content

[CALCITE-2572] Handle substring start position of less than 1#842

Closed
apilloud wants to merge 1 commit intoapache:masterfrom
apilloud:substring
Closed

[CALCITE-2572] Handle substring start position of less than 1#842
apilloud wants to merge 1 commit intoapache:masterfrom
apilloud:substring

Conversation

@apilloud
Copy link
Copy Markdown
Member

Calcite substring throws a IndexOutOfBoundsException with a position less than 1. Per the SQL standard, the position should be treated as the larger of the provided value and 1, however many implementations treat negative values as starting from the end of the string.

Extended standard:
https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions162.htm
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substring
https://spark.apache.org/docs/2.3.0/api/sql/index.html#substring
https://www.sqlite.org/lang_corefunc.html#substr

Follow the standard:
https://docs.microsoft.com/en-us/sql/t-sql/functions/substring-transact-sql?view=sql-server-2017
https://www.postgresql.org/docs/9.1/static/functions-string.html

julianhyde pushed a commit to julianhyde/calcite that referenced this pull request Sep 19, 2018
@asfgit asfgit closed this in 4f1b5ef Sep 20, 2018
@apilloud apilloud deleted the substring branch September 20, 2018 23:00
F21 pushed a commit to F21/calcite that referenced this pull request Jan 3, 2019
wangxlong pushed a commit to wangxlong/calcite that referenced this pull request Feb 13, 2020
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Aug 28, 2025
…Pilloud)

Close apache#842

Change-Id: I3b1959cd2a49fab7878709201aa6fbe41e051c19
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Mar 16, 2026
…Pilloud)

Close apache#842

Change-Id: I3b1959cd2a49fab7878709201aa6fbe41e051c19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant