-
Notifications
You must be signed in to change notification settings - Fork 30
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] Add functions for binary strings #1264
Conversation
* substring, overlay, octet_length, position Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
...er/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/ExpressionCompiler.java
Show resolved
Hide resolved
docs/sql/binary.md
Outdated
</tr> | ||
<tr> | ||
<td><code>SUBSTRING</code>(binary FROM integer)</td> | ||
<td>Generate a substring of binary starting at the given point. If the start position integer is negative, the substring starts at the position 0</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
point = offset in bytes.
Are you sure about 0? Usually negative means that it's interpreted from the end.
Moverover, SQL offsets usually start at 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres doesn't allow indexing with negative numbers, so that's what we do here.
And yeah, it should be 1 instead of 0 in terms of SQL.
docs/sql/binary.md
Outdated
</tr> | ||
<tr> | ||
<td><code>SUBSTRING</code>(binary FROM integer1 FOR integer2)</td> | ||
<td>Generate a substring of binary starting at the given point with a given length. If the start position integer is negative, the substring starts at the position 0</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
docs/sql/binary.md
Outdated
</tr> | ||
<tr> | ||
<td><code>OVERLAY</code>(binary1 PLACING binary2 FROM integer [ FOR integer2 ])</td> | ||
<td>Generate a binary string that replaces substring of binary1 with binary2. If the start position integer is negative, the new string will contain binary2 in position 0</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the FOR size is smaller than the binary2 size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If FOR size is smaller than binary2 size, it still gets replaced by the entire binary2.
} | ||
|
||
@Test | ||
public void testOctetLength() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there postgres tests with these functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we steal these too?
They can be part of a separate PR.
public void testSubstring() { | ||
this.qs( | ||
""" | ||
SELECT substring(x'123456', 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that substring(..., 1)
will generate the same result.
Then it means that values below 1 are treated as 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
...piler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/mysql/VarbinaryTests.java
Show resolved
Hide resolved
Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
Is this a user-visible change (yes/no): yes (updates the docs)
#1262