New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: remake string value functions #4145
Comments
Also SELECT TYPEOF(TRIM(both X'00' FROM X'')); should return 'varbinary'. Currently it returns 'string'. |
SELECT TRIM(1 FROM '123'); currently does nothing, and will be illegal after this fix. |
@pgulutzan I plan to rework some SQL built-in functions. What I plan to do:
I removed 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
The I executed code below in MySQL, PostgreSQL, MS SQL Server:
The results are: MySQL 5.6:
PostgreSQL 9.6:
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 deprecation: 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 causes OP_AggStep and OP_BuiltinFunction to use register P1 for the number of arguments instead of register P5. This makes it easier to use these opcodes. Needed for #4145
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 makes it easier to get a collation by a function. 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
We don't need this function, since it is easier to call finalizers directly. This patch also allows us to make further simplifications. 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.
The CHAR() function now uses the ICU macro to get characters. Part of #4145
This patch refactors RANDOMBLOB() function. Also, RANDOMBLOB(0) now returns empty string. part of #4145
This patch refactors UUID() function. Also, UUID(NULL) now returns NULL. Part of #4145
Some of the code is no longer used after changes in the SQL built-in functions. This patch removes part of the unused code. Needed for #4145
This patch removes the MEM_Dyn flag, because after changes in the SQL built-in functions, this flag is no longer used. Needed for #4145
This patch removes the MEM_Term flag, because after changes in the SQL built-in functions, this flag is no longer used. Needed for #4145
This patch forces SQL built-in function implementations to accept 'const struct Mem *' instead of just 'struct Mem *'. Needed for #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: