-
Notifications
You must be signed in to change notification settings - Fork 689
Add LEFT() and RIGHT() SQL string functions #2191
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
Conversation
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
|
what happens if we got a user function called. left or. right? |
- Case insensitivity tests (left, LEFT, Left, etc.) - Nested function tests (LEFT(RIGHT(...)), RIGHT(LEFT(...))) - Complex nesting with multiple functions - Integration with UPPER/LOWER functions - Integration with CONCAT function - Special characters handling - User-defined function compatibility test Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
User-defined functions work alongside the built-in LEFT and RIGHT functions. The built-in stdlib functions (LEFT, RIGHT) are checked first, so they take precedence. If you want to define a custom function, you'd need to use a different name like Test case 17 demonstrates this - a custom Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Implements LEFT() and RIGHT() string functions from standard SQL. These were previously unavailable because LEFT and RIGHT are reserved keywords for join operations.
Changes
Parser (
src/alasqlparser.jison)Functions (
src/55functions.js)stdlib.LEFT(string, length)- returns leftmost N characters usingsubstr(0, length)stdlib.RIGHT(string, length)- returns rightmost N characters usingsubstr(string.length - length)Tests (
test/test590.js)Example Usage
Both functions handle undefined values gracefully and follow the same patterns as existing string functions (SUBSTRING, UPPER, LOWER, etc.). User-defined functions with different names can coexist with the built-in LEFT and RIGHT functions.
Original prompt
<issue_description>Add RIGHT() and LEFT() string functions from SQL
Spawned from #588
</issue_description>
<agent_instructions>Please make a test file called test590.js verifying if this issue is still a problem.
If it is a problem try to solve it.
If you need to update the grammar of alasql, then please do small precice changes to alasqlparser.jison and then run
yarn jison && yarn testtake special care with the danger mentioned in the last message in the conversation</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@mathiasrw Yep. Still relevant. @mathiasrw Yes.You will need to add the keywords specificly as part of acceptable function names, this way it becomes valid to have those tokens as function names instead of just strings (right now the token LEFT will only be acceptable in relation to join)</comment_new>
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.