Skip to content

PostgreSQL mode: STRING_AGG with prepared statement parameter not working #3619

@coder-hugo

Description

@coder-hugo

In version 2 of the h2 database it's not possible anymore to use a prepared statement parameter for the separator of the STRING_AGG function (PostgreSQL mode).
In version 1 you could do the following:

PreparedStatement statement = connection.prepareStatement("select t1.id, string_agg(t2.value, ?) from t1 left join t2 on t2.t1_id = t1.id group by t1.id");
statement.setString(1, ",");

and you will receive a result that will look like this:

| 1 | v1,v2,v3 |
| 2 | v2,v5    |

If you do the same with version 2 of the h2 database, the result looks like this:

| 1 | v1v2v3 |
| 2 | v2v5   |

So somehow the comma gets lost in the prepared statement. If you don't use a prepared statement parameter for the separator but set it fixed to statement (string_agg(t2.value, ',')) you will receive the correct result. So in general the STRING_AGG function in the PostgresSQL mode seems to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions