Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/src/main/java/org/polypheny/db/functions/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object[]> expectedResult = ImmutableList.of(
new Object[]{"Hello"}
);
TestHelper.checkResultSet(
statement.executeQuery( "SELECT replace('Hi', 'i', 'ello')" ),
expectedResult,
true );
}
}
}


@Test
public void concatenatesTwoString() throws SQLException {
Expand Down