Postgres JDBC driver: PSQLException: syntax error at or near RETURNING

The easiest way I've done this was adding ";--" at the end of sql code:

String sql = "INSERT INTO testTable(var1, var2) values ("1","2"), ("1","2") RETURNING id;--";

PreparedStatement ps = getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();

This looks like a problem with sql2o. The comments on the bug report say:

Whe using PostgreSQL, all SELECT statements will fail with message: org.postgresql.util.PSQLException: ERROR: syntax error at or near "RETURNING"

Seems to be related to this issue

This has been fixed with version 1.1.2.

The fix requires the QuirkMode enum flag to be set to PostgreSQL when creating a new instance of sql2o. It changes default behaviour of queries to NOT fetch generated keys by default. When it is needed to fetch generated keys, the returnGeneratedKeys parameter in the generateQuery method should be set.

Since Sql2o 1.6.0, include the sql2o-postgres dependency and use new PostgresQuirks() instead of QuirksMode.