如何在自定义数据类型 (PostgreSQL) 上使用 CallableStatement (JDBC)?

问题描述

我创建了一个特定的数据类型以在我的 Postgres 数据库函数中使用:

CREATE TYPE custom_object AS (status status,operation expiration_operation,expiry_date TIMESTAMP);

函数示例如下:

CREATE OR REPLACE FUNCTION function_to_call(
in_object custom_object[]
)
RETURNS VOID
LANGUAGE plpgsql
AS $$
BEGIN

RAISE NOTICE 'ARRAY RECEIVED';
END
$$;

从 Postgres,我可以将它用于“custom_object”类型的数组:

select function_to_call(array[('Active','Expire',now() AT TIME ZONE 'UTC'),('Completed','Delete',now() AT TIME ZONE 'UTC')]::custom_object[]);

然后,从 Java 开始,我将使用 Callablestatement。

final String[][] policy = {{"Active","Expire",new Date().toString()},{"Completed",new Date().toString()}};
final Connection conn = DatabaseConnectionProvider.getConnection(appConfig);
final CallableStatement stmt = conn.prepareCall("{call function_to_call(?)}");
Array arrayL;
arrayL = conn.createArrayOf("VARCHAR",labelArray.toArray());
stmt.setArray(1,policy);

有没有办法可以按照函数的预期直接将该数组的类型声明为“custom_object”,或者我应该作为常规 varchar 数组传递然后在过程中进行一些转换?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...