diff --git a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java index f5e2552d6f..2648f47039 100644 --- a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java +++ b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java @@ -989,6 +989,15 @@ public class PostgresPlugin extends BasePlugin { urlBuilder.append(authentication.getDatabaseName()); } + /** + * JDBC connection parameter to auto resolve argument type when using prepared statements. Please note that this auto deduction of type happens only when + * the argument is bound using `setString()` method. In our case, it means that we have identified the argument data type as String. + * Quoting from doc: + * If stringtype is set to unspecified, parameters will be sent to the server as untyped values, and the server will attempt to infer an appropriate type. + * Ref: https://jdbc.postgresql.org/documentation/83/connect.html + */ + urlBuilder.append("?stringtype=unspecified"); + /* * - Ideally, it is never expected to be null because the SSL dropdown is set to a initial value. */ diff --git a/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java b/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java index f93c558c0e..afe1c66e6b 100644 --- a/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java +++ b/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java @@ -1300,6 +1300,50 @@ public class PostgresPluginTest { } + @Test + public void testPreparedStatementWithTimeZoneTimeStamp() { + DatasourceConfiguration dsConfig = createDatasourceConfiguration(); + + ActionConfiguration actionConfiguration = new ActionConfiguration(); + actionConfiguration.setBody("UPDATE public.\"users\" set " + + "created_on_tz = {{createdTS}}\n" + + " where id = 3;"); + + List pluginSpecifiedTemplates = new ArrayList<>(); + pluginSpecifiedTemplates.add(new Property("preparedStatement", "true")); + actionConfiguration.setPluginSpecifiedTemplates(pluginSpecifiedTemplates); + + ExecuteActionDTO executeActionDTO = new ExecuteActionDTO(); + List params = new ArrayList<>(); + params.add(new Param("createdTS", "2022-04-11T05:30:00Z")); + + executeActionDTO.setParams(params); + + Mono connectionCreateMono = pluginExecutor.datasourceCreate(dsConfig).cache(); + + Mono resultMono = connectionCreateMono + .flatMap(pool -> pluginExecutor.executeParameterized(pool, executeActionDTO, dsConfig, actionConfiguration)); + + StepVerifier.create(resultMono) + .assertNext(result -> { + assertTrue(result.getIsExecutionSuccess()); + }) + .verifyComplete(); + + actionConfiguration.setBody("SELECT * FROM public.\"users\" where id = 3;"); + resultMono = connectionCreateMono + .flatMap(pool -> pluginExecutor.executeParameterized(pool, executeActionDTO, dsConfig, actionConfiguration)); + + StepVerifier.create(resultMono) + .assertNext(result -> { + assertTrue(result.getIsExecutionSuccess()); + + final JsonNode node = ((ArrayNode) result.getBody()).get(0); + assertEquals(node.get("created_on_tz").asText(), "2022-04-11T05:30:00Z"); //UTC time + }) + .verifyComplete(); + } + public void testReadOnlyMode() { DatasourceConfiguration dsConfig = createDatasourceConfiguration(); dsConfig.getConnection().setMode(com.appsmith.external.models.Connection.Mode.READ_ONLY);