Skip to content
Snippets Groups Projects
Commit e01a8ff2 authored by Mergen Imeev's avatar Mergen Imeev Committed by Kirill Yukhin
Browse files

sql: rework SUBSTR() function

This patch makes SUBSTR() work according to ANSI rules for SUBSTRING()
function. Also, SUBSTR() can now work correctly with large INTEGER
values. The SUBSTR() syntax has not changed.

Part of #4145

@TarantoolBot document
Title: SUBSTR() function

SUBSTR() now works according to the ANSI rules for SUBSTRING().

Rules for SUBSTR() with 2 arguments:
1) let the first argument be VALUE, and the second argument be START;
2) VALUE should be STRING or VARBINARY, START should be INTEGER;
3) if any of arguments is NULL, NULL is returned;
4) let POS be MAX(START - 1, 0), END be length of the VALUE;
5) if POS >= END, the result is empty string;
6) if POS < END, the result will be substring of VALUE, starting from
   the position POS to the position END.

Rules for SUBSTR() with 3 arguments:
1) let the first argument be VALUE, the second argument be START, and
   the third argument be LENGTH;
2) VALUE should be STRING or VARBINARY, START and LENGTH should be
   INTEGERs;
3) if any of arguments is NULL, NULL is returned;
4) if LENGTH < 0, an error is thrown;
5) let POS be MAX(START - 1, 0), END be START + LENGTH - 1;
6) if POS >= END, the result is empty string;
7) if POS < END, the result will be substring of VALUE, starting from
   the position POS to the position END.
parent 3ec6042f
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment