提交 c8fec1e6 authored 作者: noelgrandin's avatar noelgrandin

Issue 479: Support for SUBSTRING without a FROM condition, patch from Andrew Franklin

上级 987315a9
......@@ -3155,7 +3155,7 @@ CALL UTF8TOSTRING(STRINGTOUTF8('This is a test'))
Returns a substring of a string starting at a position.
If the start index is negative, then the start index is relative to the end of the string.
The length is optional.
Also supported is: ""SUBSTRING(string FROM start [FOR length])"".
Also supported is: ""SUBSTRING(string [FROM start] [FOR length])"".
","
CALL SUBSTR('[Hello]', 2, 5);
CALL SUBSTR('Hello World', -5);
......
......@@ -39,6 +39,7 @@ Change Log
</li><li>Issue 473: PgServer missing -key option, patch from Andrew Franklin
</li><li>Issue 471: CREATE VIEW does not check user rights, patch from Andrew Franklin
</li><li>Issue 477: PgServer binary transmission of query params is unimplemented, patch from Andrew Franklin
</li><li>Issue 479: Support for SUBSTRING without a FROM condition, patch from Andrew Franklin
</li></ul>
<h2>Version 1.3.172 (2013-05-25)</h2>
......
......@@ -2243,14 +2243,28 @@ public class Parser {
break;
}
case Function.SUBSTRING: {
// Different variants include:
// SUBSTRING(X,1)
// SUBSTRING(X,1,1)
// SUBSTRING(X FROM 1 FOR 1) -- Postgres
// SUBSTRING(X FROM 1) -- Postgres
// SUBSTRING(X FOR 1) -- Postgres
function.setParameter(0, readExpression());
if (!readIf(",")) {
read("FROM");
if (readIf("FROM")) {
function.setParameter(1, readExpression());
if (readIf("FOR")) {
function.setParameter(2, readExpression());
}
} else if (readIf("FOR")) {
function.setParameter(1, ValueExpression.get(ValueInt.get(0)));
function.setParameter(2, readExpression());
} else {
read(",");
function.setParameter(1, readExpression());
if (readIf("FOR") || readIf(",")) {
if (readIf(",")) {
function.setParameter(2, readExpression());
}
}
read(")");
break;
}
......
......@@ -214,6 +214,9 @@ public class TestCompatibility extends TestBase {
Statement stat = conn.createStatement();
stat.execute("SET MODE PostgreSQL");
testLog(Math.log10(10), stat);
assertResult("ABC", stat, "SELECT SUBSTRING('ABCDEF' FOR 3)");
assertResult("BCDE", stat, "SELECT SUBSTRING('ABCDEF' FROM 2 FOR 4)");
}
private void testMySQL() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论