diff --git a/core/src/main/java/org/polypheny/db/functions/Functions.java b/core/src/main/java/org/polypheny/db/functions/Functions.java index 3fb9735e70..c30e4a8380 100644 --- a/core/src/main/java/org/polypheny/db/functions/Functions.java +++ b/core/src/main/java/org/polypheny/db/functions/Functions.java @@ -1985,6 +1985,13 @@ public static String replace( String s, String search, String replacement ) { return s.replace( search, replacement ); } + /** + * SQL {@code REPLACE(string, search, replacement)} function. + */ + public static PolyString replace( PolyString s, PolyString search, PolyString replacement ) { + return PolyString.of( s.value.replace( search.value, replacement.value ) ); + } + /** * Helper for "array element reference". Caller has already ensured that array and index are not null. Index is 1-based, per SQL. diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java index 401c40b3cb..314517e17d 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/StringFunctionsTest.java @@ -86,6 +86,22 @@ public static void stop() throws SQLException { // --------------- Tests --------------- + @Test + public void stringReplaceTest() throws SQLException { + try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) { + Connection connection = polyphenyDbConnection.getConnection(); + try ( Statement statement = connection.createStatement() ) { + List expectedResult = ImmutableList.of( + new Object[]{"Hello"} + ); + TestHelper.checkResultSet( + statement.executeQuery( "SELECT replace('Hi', 'i', 'ello')" ), + expectedResult, + true ); + } + } + } + @Test public void concatenatesTwoString() throws SQLException {