sql: remake string value functions #4145
These are functions like TRIM(), QUOTE(), SUBSTR(), HEX(), LOWER(). If we want to follow ANSI SQL, we have to:
From discussion #3879
The text was updated successfully, but these errors were encountered:
@pgulutzan I plan to rework some SQL built-in functions. What I plan to do:
How it will work:
If value of
@pgulutzan thank you for the answer! My answers below.
I was planning to drop SUBSTR() in the next release. However, with a little thought, I realized that it might not be the best idea to just drop it without proper deprecation. @unera @kyukhin what do you think? We can just leave it, but I suggest making it a smaller version of ANSI's SUBSTRING() function. It will have the same rules as SUBSTRING(), but it will not have its own syntax and will not be
About your program, that simulates ANSI - I believe the SQL-2011 standard (6.30 , in
I executed code below in MySQL, PostgreSQL, MS SQL Server:
The results are:
MS SQL Server 2017:
In addition, MySQL and PostgreSQL can work with both
For us the result will be:
What do you think about such difference?
Also, after some thought, I came to the conclusion that I would add
Re "1) Let S1 be the larger of S and 1 (one)":
Re "I executed code below in MySQL, PostgreSQL, MS SQL Server":
Re "For us the result will be:"
Re "USING OCTETS":
Re my other questions:
@pgulutzan you are right: I wrongly interpreted '' as NULL and I missed f)i).
About UUID as an argument - I am not sure how to implement this. I mean, should it work as
About non-integer arguments - if an argument can be implicitly cast to INTEGER, than there is no reason to not accept it.
In a few days I will submit a document in which I describe what I plan to do with the existing SQL built-in functions and what SQL built-in function I plan to add in the next release. There will be quite a few questions that I hope you can help us resolve.
I have published a blog post about the SQL substring function:
This patch moves the initialization of sql_context out of the VDBE. This allows us to remove the opcodes OP_BuiltinFunction0 and OP_AggStep0, which work in a rather strange way. Moreover, due to the changes these opcodes make to the VDBEs, it is possible that the estimated size of the VDBE may change during execution of VDBE, which could lead to various problems. Needed for #4145
This patch introduces function mem_append(). This function appends the given string to the end of the STRING or VARBINARY contained in MEM. In case MEM needs to increase the size of allocated memory, additional memory is allocated in an attempt to reduce the total number of allocations. The main use of this function is to add multiple strings to a single MEM. Needed for #4145
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.