【问题标题】:How to call PostgreSQL function with array of rowtype as parameter from Java如何从Java调用具有行类型数组作为参数的PostgreSQL函数
【发布时间】:2014-08-26 17:55:54
【问题描述】:

如何从 Java 应用程序(应用程序是 Spring Web 应用程序)调用以 rowtype 数组作为参数的 postgres 函数?
当然我可以重构我的函数并使用几个原始类型的数组,但是在应用程序端函数调用会很丑。

CREATE OR REPLACE FUNCTION process_orders
(
  order_array orders[]
)
RETURNS bigint AS
$BODY$
BEGIN
    -- bla bla bla :)
    RETURN 0;
END;
$BODY$

LANGUAGE plpgsql;

【问题讨论】:

    标签: postgresql jdbc types row spring-jdbc


    【解决方案1】:

    我希望类似函数的 row constructor 不适用于 JDBC。请改用上述参数的文本表示
    例如,如果您的表是tbl (id int, txt text)

    SELECT process_orders('{"(1,txt)","(1,txt)"}')
    

    或者(在重载函数面前要明确):

    SELECT process_orders('{"(1,txt)","(1,txt)"}'::tbl[])
    

    带空格和特殊字符的示例:

    SELECT process_orders('"(1,txt)","(1,\"txt with space and '\")"}')
    

    如何判断语法正确?

    让 Postgres 告诉你:
    SQL Fiddle.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多